69
69
public class Mailer {
70
70
71
71
private static final Logger logger = LoggerFactory .getLogger (Mailer .class );
72
-
72
+
73
73
/**
74
74
* Encoding used for setting body text, email address, headers, reply-to fields etc. ({@value #CHARACTER_ENCODING}).
75
75
*/
@@ -101,22 +101,22 @@ public class Mailer {
101
101
* Default constructor, stores the given mail session for later use. Assumes that *all* properties used to make a connection are
102
102
* configured (host, port, authentication and transport protocol settings).
103
103
* <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 .
106
106
*
107
107
* @param session A preconfigured mail {@link Session} object with which a {@link Message} can be produced.
108
108
*/
109
109
public Mailer (final Session session ) {
110
110
this .session = session ;
111
- this .emailAddressValidationCriteria = new EmailAddressValidationCriteria ( true , true ) ;
111
+ this .emailAddressValidationCriteria = null ;
112
112
}
113
113
114
114
/**
115
115
* Overloaded constructor which produces a new {@link Session} on the fly. Use this if you don't have a mail session configured in your
116
116
* web container, or Spring context etc.
117
117
* <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 .
120
120
*
121
121
* @param host The address URL of the SMTP server to be used.
122
122
* @param port The port of the SMTP server.
@@ -134,7 +134,7 @@ public Mailer(final String host, final Integer port, final String username, fina
134
134
}
135
135
this .transportStrategy = transportStrategy ;
136
136
this .session = createMailSession (host , port , username , password );
137
- this .emailAddressValidationCriteria = new EmailAddressValidationCriteria ( true , true ) ;
137
+ this .emailAddressValidationCriteria = null ;
138
138
}
139
139
140
140
/**
@@ -287,7 +287,7 @@ public boolean validate(final Email email)
287
287
throw new MailException (MailException .MISSING_RECIPIENT );
288
288
} else if (email .getFromRecipient () == null ) {
289
289
throw new MailException (MailException .MISSING_SENDER );
290
- } else {
290
+ } else if ( emailAddressValidationCriteria != null ) {
291
291
if (!EmailValidationUtil .isValid (email .getFromRecipient ().getAddress (), emailAddressValidationCriteria )) {
292
292
throw new MailException (String .format (MailException .INVALID_SENDER , email ));
293
293
}
@@ -362,7 +362,8 @@ private void setReplyTo(final Email email, final Message message)
362
362
throws UnsupportedEncodingException , MessagingException {
363
363
final Recipient replyToRecipient = email .getReplyToRecipient ();
364
364
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 );
366
367
message .setReplyTo (new Address [] { replyToAddress });
367
368
}
368
369
}
@@ -516,7 +517,7 @@ private class MimeEmailMessageWrapper {
516
517
517
518
/**
518
519
* 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.
520
521
*
521
522
* @param emailAddressValidationCriteria Refer to
522
523
* {@link EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)}.
0 commit comments