Class JMail

java.lang.Object
com.sanctionco.jmail.JMail

public final class JMail extends Object
Provides static methods to validate an email address using standard RFC validation, or to create a new EmailValidator.
  • Method Details

    • validator

      public static EmailValidator validator()
      Returns a new instance of EmailValidator. In general, you should favor using strictValidator() instead of this method, as this method will allow IP address domain literals, dotless domains, and explicit source routing unless configured separately.
      Returns:
      the new EmailValidator instance
    • strictValidator

      public static EmailValidator strictValidator()
      Returns a new instance of EmailValidator with stricter rules applied to the validator. The following rules are applied and do not need to be added:
      • The email address cannot have an IP Address domain
      • The email address cannot have a dotless domain
      • The email address cannot have explicit source routing
      Returns:
      the new EmailValidator instance
    • isValid

      public static boolean isValid(String email)
      Return true if the given email address passes basic RFC validation. See tryParse(String) for details on what is required of an email address within basic validation.
      Parameters:
      email - the email address to validate
      Returns:
      true if the given string is a valid email address, false otherwise
    • isInvalid

      public static boolean isInvalid(String email)
      Return true if the given email address fails basic RFC validation. See tryParse(String) for details on what is required of an email address within basic validation.
      Parameters:
      email - the email address to validate
      Returns:
      true if the given string is not a valid email address, false otherwise
    • enforceValid

      public static void enforceValid(String email) throws InvalidEmailException
      Require that the given email address passes basic RFC validation, throwing InvalidEmailException if the address is invalid. See tryParse(String) for details on what is required of an email address within basic validation.
      Parameters:
      email - the email address to validate
      Throws:
      InvalidEmailException - if the validation fails
    • tryParse

      public static Optional<Email> tryParse(String email)
      Parse the given email address into a new Email object. This method does basic validation on the input email address. This method does not claim to be 100% accurate in determining if an email address is valid or invalid due to the complexity of the email RFC standards. That being said, if you come across an email address that you expect to be valid that fails validation, or vice-versa, please open an issue at the GitHub repo so it can be fixed.

      In general, this method should be more or less compliant with the latest RFCs.

      Parameters:
      email - the email address to parse
      Returns:
      an Optional containing the parsed Email, or empty if the email is invalid