javax.mail.internet.InternetAddress#validate ( )源码实例Demo

下面列出了javax.mail.internet.InternetAddress#validate ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openemm   文件: JavaMailServiceImpl.java
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]);
}
 
源代码2 项目: MusicStore   文件: CatalogController.java
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;
}
 
源代码3 项目: MusicStore   文件: OrderController.java
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;
}
 
源代码4 项目: MusicStore   文件: NewsletterController.java
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;
}
 
源代码5 项目: Java-for-Data-Science   文件: ValidatingData.java
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";
	}
}
 
源代码6 项目: blackduck-alert   文件: EmailGlobalTestAction.java
@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");
}
 
源代码7 项目: easybuggy   文件: EmailUtils.java
/**
 * 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;
}
 
源代码8 项目: nomulus   文件: Registrar.java
/** 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;
}
 
@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);
    }
}
 
源代码10 项目: CodeDefenders   文件: LoginManager.java
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;
}
 
源代码11 项目: james-project   文件: CreationMessage.java
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;
}
 
源代码12 项目: incubator-pinot   文件: EmailUtils.java
/**
 * 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;
  }
}
 
源代码13 项目: openhab1-addons   文件: PushbulletAPIConnector.java
/**
 * 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;
    }
}
 
源代码14 项目: metanome-algorithms   文件: DataTypes.java
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;
  }
 
源代码15 项目: spring-analysis-note   文件: MimeMessageHelper.java
/**
 * 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();
	}
}
 
源代码16 项目: java-technology-stack   文件: MimeMessageHelper.java
/**
 * 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();
	}
}
 
源代码17 项目: lams   文件: MimeMessageHelper.java
/**
 * 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();
	}
}
 
源代码18 项目: spring4-understanding   文件: MimeMessageHelper.java
/**
 * 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();
	}
}