Class MailerHelper

java.lang.Object
org.simplejavamail.mailer.MailerHelper

public class MailerHelper extends Object
If you don't need to actually connect to a server and/or send anything, then this class still provides you with some functionality otherwise triggered only by a Mailer.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    scanForInjectionAttack(@Nullable String value, String valueLabel)
     
    static void
    scanForInjectionAttacks(@NotNull org.simplejavamail.api.email.Email email)
    Checks the following headers for suspicious content (newlines and characters): subject every header name and value every attachment name, content ID, nested datasource name and description every embedded image name, content ID, nested datasource name and description from recipient name and address every replyTo recipient name and address, if provided bounceTo recipient name and address, if provided every TO/CC/BCC recipient name and address disposition-notification-to recipient name and address, if provided return-receipt-to recipient name and address, if provided
    static jakarta.mail.internet.MimeMessage
    signAndOrEncryptMessageWithSmime(@NotNull jakarta.mail.Session session, @NotNull jakarta.mail.internet.MimeMessage messageToProtect, @NotNull org.simplejavamail.api.email.Email emailContainingSmimeDetails)
    Depending on the Email configuration, signs and then encrypts message (both steps optional), using the S/MIME module.
    static jakarta.mail.internet.MimeMessage
    signMessageWithDKIM(@NotNull jakarta.mail.internet.MimeMessage messageToSign, @NotNull org.simplejavamail.api.email.Email emailContainingSigningDetails)
     
    static boolean
    validate(@NotNull org.simplejavamail.api.email.Email email)
    Delegates to #validate(Email, EmailValidator) with a null validator.
    static boolean
    validate(@NotNull org.simplejavamail.api.email.Email email, @Nullable com.sanctionco.jmail.EmailValidator emailValidator)
    Runs completeness, address and CRLF-injection validation against the supplied Email.
    static void
    validateAddresses(@NotNull org.simplejavamail.api.email.Email email, @Nullable com.sanctionco.jmail.EmailValidator emailValidator)
    If email validator is provided, checks: from recipient all TO/CC/BCC recipients reply-to recipient, if provided bounce-to recipient, if provided disposition-notification-to recipient, if provided return-receipt-to recipient, if provided
    static void
    validateCompleteness(@NotNull org.simplejavamail.api.email.Email email)
    Checks whether the following RFC 5322 mandatory properties are present: there are recipients if there is a sender
    static boolean
    validateLenient(@NotNull org.simplejavamail.api.email.Email email)
    Delegate to #validateLenient(Email, EmailValidator) with a null validator.
    static boolean
    validateLenient(@NotNull org.simplejavamail.api.email.Email email, @Nullable com.sanctionco.jmail.EmailValidator emailValidator)
    Runs the same completeness, address and CRLF-injection checks as validate(Email, EmailValidator), but logs findings instead of throwing them to the caller.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MailerHelper

      public MailerHelper()
  • Method Details

    • validate

      public static boolean validate(@NotNull @NotNull org.simplejavamail.api.email.Email email) throws org.simplejavamail.MailException
      Delegates to #validate(Email, EmailValidator) with a null validator.
      Throws:
      org.simplejavamail.MailException
    • validate

      public static boolean validate(@NotNull @NotNull org.simplejavamail.api.email.Email email, @Nullable @Nullable com.sanctionco.jmail.EmailValidator emailValidator) throws org.simplejavamail.MailException
      Runs completeness, address and CRLF-injection validation against the supplied Email. If emailValidator is null, address-format validation is skipped while encoded-word address protection remains active.
      Throws:
      org.simplejavamail.MailException
      See Also:
    • validateLenient

      public static boolean validateLenient(@NotNull @NotNull org.simplejavamail.api.email.Email email) throws org.simplejavamail.MailException
      Delegate to #validateLenient(Email, EmailValidator) with a null validator.
      Throws:
      org.simplejavamail.MailException
    • validateLenient

      public static boolean validateLenient(@NotNull @NotNull org.simplejavamail.api.email.Email email, @Nullable @Nullable com.sanctionco.jmail.EmailValidator emailValidator) throws org.simplejavamail.MailException
      Runs the same completeness, address and CRLF-injection checks as validate(Email, EmailValidator), but logs findings instead of throwing them to the caller.
      Throws:
      org.simplejavamail.MailException
      See Also:
    • validateCompleteness

      public static void validateCompleteness(@NotNull @NotNull org.simplejavamail.api.email.Email email)
      Checks whether the following RFC 5322 mandatory properties are present:
      1. there are recipients
      2. if there is a sender
    • validateAddresses

      public static void validateAddresses(@NotNull @NotNull org.simplejavamail.api.email.Email email, @Nullable @Nullable com.sanctionco.jmail.EmailValidator emailValidator)
      If email validator is provided, checks:
      1. from recipient
      2. all TO/CC/BCC recipients
      3. reply-to recipient, if provided
      4. bounce-to recipient, if provided
      5. disposition-notification-to recipient, if provided
      6. return-receipt-to recipient, if provided
    • scanForInjectionAttacks

      public static void scanForInjectionAttacks(@NotNull @NotNull org.simplejavamail.api.email.Email email)
      Checks the following headers for suspicious content (newlines and characters):
      1. subject
      2. every header name and value
      3. every attachment name, content ID, nested datasource name and description
      4. every embedded image name, content ID, nested datasource name and description
      5. from recipient name and address
      6. every replyTo recipient name and address, if provided
      7. bounceTo recipient name and address, if provided
      8. every TO/CC/BCC recipient name and address
      9. disposition-notification-to recipient name and address, if provided
      10. return-receipt-to recipient name and address, if provided
      See Also:
    • scanForInjectionAttack

      public static void scanForInjectionAttack(@Nullable @Nullable String value, String valueLabel)
      Parameters:
      value - Value checked for suspicious newline characters "\n", "\r" and the URL-encoded newline "%0A" (as acknowledged by SMTP servers).
      valueLabel - The name of the field being checked, used for reporting exceptions.
      See Also:
    • signMessageWithDKIM

      public static jakarta.mail.internet.MimeMessage signMessageWithDKIM(@NotNull @NotNull jakarta.mail.internet.MimeMessage messageToSign, @NotNull @NotNull org.simplejavamail.api.email.Email emailContainingSigningDetails)
      See Also:
      • DKIMModule.signMessageWithDKIM(Email, MimeMessage, DkimConfig, Recipient)
    • signAndOrEncryptMessageWithSmime

      public static jakarta.mail.internet.MimeMessage signAndOrEncryptMessageWithSmime(@NotNull @NotNull jakarta.mail.Session session, @NotNull @NotNull jakarta.mail.internet.MimeMessage messageToProtect, @NotNull @NotNull org.simplejavamail.api.email.Email emailContainingSmimeDetails)
      Depending on the Email configuration, signs and then encrypts message (both steps optional), using the S/MIME module.
      See Also:
      • SMIMEModule.signMessageWithSmime(Session, Email, MimeMessage, SmimeSigningConfig)
      • SMIMEModule.encryptMessageWithSmime(Session, Email, MimeMessage, SmimeEncryptionConfig)