Package org.simplejavamail.mailer
Class MailerHelper
java.lang.Object
org.simplejavamail.mailer.MailerHelper
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic voidscanForInjectionAttack(@Nullable String value, String valueLabel) static voidscanForInjectionAttacks(@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 providedstatic jakarta.mail.internet.MimeMessagesignAndOrEncryptMessageWithSmime(@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.MimeMessagesignMessageWithDKIM(@NotNull jakarta.mail.internet.MimeMessage messageToSign, @NotNull org.simplejavamail.api.email.Email emailContainingSigningDetails) static booleanvalidate(@NotNull org.simplejavamail.api.email.Email email) Delegates to #validate(Email, EmailValidator) with a null validator.static booleanvalidate(@NotNull org.simplejavamail.api.email.Email email, @Nullable com.sanctionco.jmail.EmailValidator emailValidator) Runs completeness, address and CRLF-injection validation against the suppliedEmail.static voidvalidateAddresses(@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 providedstatic voidvalidateCompleteness(@NotNull org.simplejavamail.api.email.Email email) Checks whether the following RFC 5322 mandatory properties are present: there are recipients if there is a senderstatic booleanvalidateLenient(@NotNull org.simplejavamail.api.email.Email email) Delegate to #validateLenient(Email, EmailValidator) with a null validator.static booleanvalidateLenient(@NotNull org.simplejavamail.api.email.Email email, @Nullable com.sanctionco.jmail.EmailValidator emailValidator) Runs the same completeness, address and CRLF-injection checks asvalidate(Email, EmailValidator), but logs findings instead of throwing them to the caller.
-
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 suppliedEmail. IfemailValidatorisnull, 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 asvalidate(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:- there are recipients
- 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:- 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
-
scanForInjectionAttacks
public static void scanForInjectionAttacks(@NotNull @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
- See Also:
-
scanForInjectionAttack
- 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:
-
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:
-