Java Code Examples for javax.mail.internet.InternetAddress#validate()
The following examples show how to use
javax.mail.internet.InternetAddress#validate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaMailServiceImpl.java From openemm with GNU Affero General Public License v3.0 | 6 votes |
private static InternetAddress[] getEmailAddressesFromList(String listString) { List<InternetAddress> emailAddresses = new ArrayList<>(); for (String address : AgnUtils.splitAndNormalizeEmails(listString)) { address = StringUtils.trimToEmpty(address); if(AgnUtils.isEmailValid(address)) { try { InternetAddress nextAddress = new InternetAddress(address); nextAddress.validate(); emailAddresses.add(nextAddress); } catch (AddressException e) { logger.error("Invalid Emailaddress found: " + address); } } } return emailAddresses.toArray(new InternetAddress[0]); }
Example 2
Source File: NewsletterController.java From MusicStore with MIT License | 6 votes |
private boolean isValid(String firstName, String lastName, String email) { boolean valid = true; if (firstName == null || lastName == null || email == null) { valid = false; } else if (firstName.isEmpty() || lastName.isEmpty() || email.isEmpty()) { valid = false; } else { try { InternetAddress emailAddress = new InternetAddress(email); emailAddress.validate(); } catch (AddressException e) { valid = false; } } return valid; }
Example 3
Source File: OrderController.java From MusicStore with MIT License | 6 votes |
private boolean isValid(String firstName, String lastName, String email, String companyName, String address1, String address2, String city, String county, String postCode, String country) { boolean valid = true; if (firstName == null || lastName == null || email == null || address1 == null || city == null || county == null || postCode == null || country == null) { valid = false; } else if (firstName.isEmpty() || lastName.isEmpty() || email.isEmpty() || address1.isEmpty() || city.isEmpty() || county.isEmpty() || postCode.isEmpty() || country.isEmpty()) { valid = false; } else { try { InternetAddress emailAddress = new InternetAddress(email); emailAddress.validate(); } catch (AddressException e) { valid = false; } } return valid; }
Example 4
Source File: CatalogController.java From MusicStore with MIT License | 6 votes |
private boolean isValid(String firstName, String lastName, String email) { boolean valid = true; if (firstName == null || firstName.isEmpty()) { valid = false; } else if (lastName == null || lastName.isEmpty()) { valid = false; } else { // validate email address try { InternetAddress emailAddress = new InternetAddress(email); emailAddress.validate(); } catch (AddressException e) { valid = false; } } return valid; }
Example 5
Source File: PushbulletAPIConnector.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * Inner method checking if email address is valid. * * @param email * @return */ private static boolean isValidEmail(String email) { try { InternetAddress emailAddr = new InternetAddress(email); emailAddr.validate(); return true; } catch (AddressException e) { return false; } }
Example 6
Source File: EmailUtils.java From incubator-pinot with Apache License 2.0 | 5 votes |
/** * Check if given email is a valid email * @param email * @return */ public static boolean isValidEmailAddress(String email) { try { Validate.notEmpty(email); InternetAddress emailAddr = new InternetAddress(email); emailAddr.validate(); return true; } catch (Exception e) { return false; } }
Example 7
Source File: CreationMessage.java From james-project with Apache License 2.0 | 5 votes |
public boolean isValid(String email) { boolean result = true; try { InternetAddress emailAddress = new InternetAddress(email); // verrrry permissive validator ! emailAddress.validate(); } catch (AddressException ex) { result = false; } return result; }
Example 8
Source File: LoginManager.java From CodeDefenders with GNU Lesser General Public License v3.0 | 5 votes |
public static boolean validEmailAddress(String email) { if (email == null) return false; boolean result = true; try { InternetAddress emailAddr = new InternetAddress(email); emailAddr.validate(); } catch (AddressException ex) { result = false; } return result; }
Example 9
Source File: MetadataServiceImpl.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@Override public void checkMetadataFormat(final MetadataFormat format, final String value, final ApiEntity api) { try { String decodedValue = value; if (api != null && !isBlank(value) && value.startsWith("${")) { Template template = new Template(value, new StringReader(value), freemarkerConfiguration); decodedValue = FreeMarkerTemplateUtils.processTemplateIntoString(template, Collections.singletonMap("api", api)); } if (isBlank(decodedValue)) { return; } switch (format) { case BOOLEAN: Boolean.valueOf(decodedValue); break; case URL: new URL(decodedValue); break; case MAIL: final InternetAddress email = new InternetAddress(decodedValue); email.validate(); break; case DATE: final SimpleDateFormat sdf = new SimpleDateFormat("YYYY-mm-dd"); sdf.setLenient(false); sdf.parse(decodedValue); break; case NUMERIC: Double.valueOf(decodedValue); break; } } catch (final Exception e) { LOGGER.error("Error occurred while trying to validate format '{}' of value '{}'", format, value, e); throw new TechnicalManagementException("Error occurred while trying to validate format " + format + " of value " + value, e); } }
Example 10
Source File: Registrar.java From nomulus with Apache License 2.0 | 5 votes |
/** Verifies that the email address in question is not null and has a valid format. */ static String checkValidEmail(String email) { checkNotNull(email, "Provided email was null"); try { InternetAddress internetAddress = new InternetAddress(email, true); internetAddress.validate(); } catch (AddressException e) { throw new IllegalArgumentException( String.format("Provided email %s is not a valid email address", email)); } return email; }
Example 11
Source File: EmailUtils.java From easybuggy with Apache License 2.0 | 5 votes |
/** * Validate the given string as E-mail address. * * @param mailAddress Mail address */ public static boolean isValidEmailAddress(String mailAddress) { boolean result = true; try { InternetAddress emailAddr = new InternetAddress(mailAddress); emailAddr.validate(); } catch (AddressException e) { log.debug("Mail address is invalid: " + mailAddress, e); result = false; } return result; }
Example 12
Source File: EmailGlobalTestAction.java From blackduck-alert with Apache License 2.0 | 5 votes |
@Override public MessageResult testConfig(String configId, FieldModel fieldModel, FieldAccessor registeredFieldValues) throws IntegrationException { Set<String> emailAddresses = Set.of(); String destination = fieldModel.getFieldValue(TestAction.KEY_DESTINATION_NAME).orElse(""); if (StringUtils.isNotBlank(destination)) { try { InternetAddress emailAddr = new InternetAddress(destination); emailAddr.validate(); } catch (AddressException ex) { throw new AlertException(String.format("%s is not a valid email address. %s", destination, ex.getMessage())); } emailAddresses = Set.of(destination); } EmailProperties emailProperties = new EmailProperties(registeredFieldValues); ComponentItem.Builder componentBuilder = new ComponentItem.Builder() .applyCategory("Test") .applyOperation(ItemOperation.ADD) .applyComponentData("Component", "Global Email Configuration") .applyCategoryItem("Message", "This is a test message from Alert.") .applyNotificationId(1L); ProviderMessageContent.Builder builder = new ProviderMessageContent.Builder() .applyProvider("Test Provider", ProviderProperties.UNKNOWN_CONFIG_ID, "Test Provider Config") .applyTopic("Message Content", "Test from Alert") .applyAllComponentItems(List.of(componentBuilder.build())); ProviderMessageContent messageContent = builder.build(); EmailAttachmentFormat attachmentFormat = registeredFieldValues.getString(EmailDescriptor.KEY_EMAIL_ATTACHMENT_FORMAT) .map(EmailAttachmentFormat::getValueSafely) .orElse(EmailAttachmentFormat.NONE); emailChannel.sendMessage(emailProperties, emailAddresses, "Test from Alert", "", attachmentFormat, MessageContentGroup.singleton(messageContent)); return new MessageResult("Message sent"); }
Example 13
Source File: ValidatingData.java From Java-for-Data-Science with MIT License | 5 votes |
public static String validateEmailStandard(String email){ try{ InternetAddress testEmail = new InternetAddress(email); testEmail.validate(); return email + " is a valid email address"; }catch(AddressException e){ return email + " is not a valid email address"; } }
Example 14
Source File: DataTypes.java From metanome-algorithms with Apache License 2.0 | 4 votes |
public static boolean isEmail(String email) { try { // Create InternetAddress object and validated the email address. InternetAddress internetAddress = new InternetAddress(email); internetAddress.validate(); } catch (Exception e) { return false; } return true; }
Example 15
Source File: MimeMessageHelper.java From spring4-understanding with Apache License 2.0 | 2 votes |
/** * Validate the given mail address. * Called by all of MimeMessageHelper's address setters and adders. * <p>Default implementation invokes {@code InternetAddress.validate()}, * provided that address validation is activated for the helper instance. * <p>Note that this method will just work on JavaMail >= 1.3. You can override * it for validation on older JavaMail versions or for custom validation. * @param address the address to validate * @throws AddressException if validation failed * @see #isValidateAddresses() * @see javax.mail.internet.InternetAddress#validate() */ protected void validateAddress(InternetAddress address) throws AddressException { if (isValidateAddresses()) { address.validate(); } }
Example 16
Source File: MimeMessageHelper.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Validate the given mail address. * Called by all of MimeMessageHelper's address setters and adders. * <p>Default implementation invokes {@code InternetAddress.validate()}, * provided that address validation is activated for the helper instance. * <p>Note that this method will just work on JavaMail >= 1.3. You can override * it for validation on older JavaMail versions or for custom validation. * @param address the address to validate * @throws AddressException if validation failed * @see #isValidateAddresses() * @see javax.mail.internet.InternetAddress#validate() */ protected void validateAddress(InternetAddress address) throws AddressException { if (isValidateAddresses()) { address.validate(); } }
Example 17
Source File: MimeMessageHelper.java From java-technology-stack with MIT License | 2 votes |
/** * Validate the given mail address. * Called by all of MimeMessageHelper's address setters and adders. * <p>Default implementation invokes {@code InternetAddress.validate()}, * provided that address validation is activated for the helper instance. * <p>Note that this method will just work on JavaMail >= 1.3. You can override * it for validation on older JavaMail versions or for custom validation. * @param address the address to validate * @throws AddressException if validation failed * @see #isValidateAddresses() * @see javax.mail.internet.InternetAddress#validate() */ protected void validateAddress(InternetAddress address) throws AddressException { if (isValidateAddresses()) { address.validate(); } }
Example 18
Source File: MimeMessageHelper.java From spring-analysis-note with MIT License | 2 votes |
/** * Validate the given mail address. * Called by all of MimeMessageHelper's address setters and adders. * <p>Default implementation invokes {@code InternetAddress.validate()}, * provided that address validation is activated for the helper instance. * <p>Note that this method will just work on JavaMail >= 1.3. You can override * it for validation on older JavaMail versions or for custom validation. * @param address the address to validate * @throws AddressException if validation failed * @see #isValidateAddresses() * @see javax.mail.internet.InternetAddress#validate() */ protected void validateAddress(InternetAddress address) throws AddressException { if (isValidateAddresses()) { address.validate(); } }