You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by sg...@apache.org on 2008/12/29 18:29:54 UTC
svn commit: r729954 -
/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java
Author: sgoeschl
Date: Mon Dec 29 09:29:53 2008
New Revision: 729954
URL: http://svn.apache.org/viewvc?rev=729954&view=rev
Log:
[EMAIL-70] Only creating a new mail session if mail authentication is required and username/password is supplied. If no username/password is supplied than use the given mail session assuming that it uses an authenticator.
Modified:
commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java
Modified: commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java?rev=729954&r1=729953&r2=729954&view=diff
==============================================================================
--- commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java (original)
+++ commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java Mon Dec 29 09:29:53 2008
@@ -391,20 +391,38 @@
}
/**
- * Supply a mail Session object to use
+ * Supply a mail Session object to use. Please note that passing
+ * a username and password (in the case of mail authentication) will
+ * create a new mail session with a DefaultAuthenticator. This is a
+ * convience but might come unexpected.
+ *
* @param aSession mail session to be used
* @since 1.0
*/
public void setMailSession(Session aSession)
{
+ EmailUtils.notNull(aSession, "no mail session supplied");
+
Properties sessionProperties = aSession.getProperties();
String auth = sessionProperties.getProperty(MAIL_SMTP_AUTH);
+
if ("true".equalsIgnoreCase(auth))
{
String userName = sessionProperties.getProperty(MAIL_SMTP_USER);
String password = sessionProperties.getProperty(MAIL_SMTP_PASSWORD);
- this.authenticator = new DefaultAuthenticator(userName, password);
- this.session = Session.getInstance(sessionProperties, this.authenticator);
+
+ if(EmailUtils.isNotEmpty(userName) && EmailUtils.isNotEmpty(password))
+ {
+ // only create a new mail session with an authenticator if
+ // authentication is required and no user name is given
+ this.authenticator = new DefaultAuthenticator(userName, password);
+ this.session = Session.getInstance(sessionProperties, this.authenticator);
+ }
+ else
+ {
+ // assume that the given mail session contains a working authenticator
+ this.session = aSession;
+ }
}
else
{