6969public class Mailer {
7070
7171 private static final Logger logger = LoggerFactory .getLogger (Mailer .class );
72-
72+
7373 /**
7474 * Encoding used for setting body text, email address, headers, reply-to fields etc. ({@value #CHARACTER_ENCODING}).
7575 */
@@ -101,22 +101,22 @@ public class Mailer {
101101 * Default constructor, stores the given mail session for later use. Assumes that *all* properties used to make a connection are
102102 * configured (host, port, authentication and transport protocol settings).
103103 * <p>
104- * Also defines a default email address validation criteria object, which remains true to RFC 2822, meaning allowing both domain
105- * literals and quoted identifiers (see {@link EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)}) .
104+ * Also leaves email address validation criteria empty so that no validation is being performed. Validation errors will come from the
105+ * smtp server instead .
106106 *
107107 * @param session A preconfigured mail {@link Session} object with which a {@link Message} can be produced.
108108 */
109109 public Mailer (final Session session ) {
110110 this .session = session ;
111- this .emailAddressValidationCriteria = new EmailAddressValidationCriteria ( true , true ) ;
111+ this .emailAddressValidationCriteria = null ;
112112 }
113113
114114 /**
115115 * Overloaded constructor which produces a new {@link Session} on the fly. Use this if you don't have a mail session configured in your
116116 * web container, or Spring context etc.
117117 * <p>
118- * Also defines a default email address validation criteria object, which remains true to RFC 2822, meaning allowing both domain
119- * literals and quoted identifiers (see {@link EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)}) .
118+ * Also leaves email address validation criteria empty so that no validation is being performed. Validation errors will come from the
119+ * smtp server instead .
120120 *
121121 * @param host The address URL of the SMTP server to be used.
122122 * @param port The port of the SMTP server.
@@ -134,7 +134,7 @@ public Mailer(final String host, final Integer port, final String username, fina
134134 }
135135 this .transportStrategy = transportStrategy ;
136136 this .session = createMailSession (host , port , username , password );
137- this .emailAddressValidationCriteria = new EmailAddressValidationCriteria ( true , true ) ;
137+ this .emailAddressValidationCriteria = null ;
138138 }
139139
140140 /**
@@ -287,7 +287,7 @@ public boolean validate(final Email email)
287287 throw new MailException (MailException .MISSING_RECIPIENT );
288288 } else if (email .getFromRecipient () == null ) {
289289 throw new MailException (MailException .MISSING_SENDER );
290- } else {
290+ } else if ( emailAddressValidationCriteria != null ) {
291291 if (!EmailValidationUtil .isValid (email .getFromRecipient ().getAddress (), emailAddressValidationCriteria )) {
292292 throw new MailException (String .format (MailException .INVALID_SENDER , email ));
293293 }
@@ -362,7 +362,8 @@ private void setReplyTo(final Email email, final Message message)
362362 throws UnsupportedEncodingException , MessagingException {
363363 final Recipient replyToRecipient = email .getReplyToRecipient ();
364364 if (replyToRecipient != null ) {
365- InternetAddress replyToAddress = new InternetAddress (replyToRecipient .getAddress (), replyToRecipient .getName (), CHARACTER_ENCODING );
365+ InternetAddress replyToAddress = new InternetAddress (replyToRecipient .getAddress (), replyToRecipient .getName (),
366+ CHARACTER_ENCODING );
366367 message .setReplyTo (new Address [] { replyToAddress });
367368 }
368369 }
@@ -516,7 +517,7 @@ private class MimeEmailMessageWrapper {
516517
517518 /**
518519 * Overrides the default email address validation restrictions when validating and sending emails using the current <code>Mailer</code>
519- * instance.
520+ * instance. By default no validation will be performed by simple-java-mail, until a criteria object has been set.
520521 *
521522 * @param emailAddressValidationCriteria Refer to
522523 * {@link EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)}.
0 commit comments