commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason <ja...@plutext.org>
Subject Re: [EMAIL] Using Apache Commons Email and Google
Date Wed, 09 Jul 2014 00:57:15 GMT
Resurrecting this old post, I found that in order to Authenticate with SASL 
using
https://code.google.com/p/google-mail-oauth2-tools/source/browse/#svn%2Ftrunk%2Fjava%2Fcom%2Fgoogle%2Fcode%2Fsamples%2Foauth2
it was necessary to invoke 

     Transport.send(this.message, this.getFromAddress().getAddress(), ""); 

rather than

     Transport.send(this.message);

The attached patch does this.  The if condition may need to be tweaked to
make it more specific to google-mail-oauth2.

cheers .. Jason

Index: src/main/java/org/apache/commons/mail/Email.java
===================================================================
--- src/main/java/org/apache/commons/mail/Email.java	(revision 1608640)
+++ src/main/java/org/apache/commons/mail/Email.java	(working copy)
@@ -41,6 +41,7 @@
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
+
 /**
  * The base class for all email messages.  This class sets the
  * sender's email &amp; name, receiver's email &amp; name, subject, and the
@@ -1397,7 +1398,15 @@
 
         try
         {
-            Transport.send(this.message);
+        	if
("XOAUTH2".equals(this.session.getProperty("mail.smtp.sasl.mechanisms"))) {
+        		/* In order to Authenticate with SASL 
+        		 * using
https://code.google.com/p/google-mail-oauth2-tools/source/browse/#svn%2Ftrunk%2Fjava%2Fcom%2Fgoogle%2Fcode%2Fsamples%2Foauth2
+        		 */
+        		Transport.send(this.message, this.getFromAddress().getAddress(),
""); 
+        		
+        	} else {
+        		Transport.send(this.message);
+        	}
             return this.message.getMessageID();
         }
         catch (final Throwable t)
Index: pom.xml
===================================================================
--- pom.xml	(revision 1608640)
+++ pom.xml	(working copy)
@@ -227,7 +229,7 @@
         <dependency>
             <groupId>javax.mail</groupId>
             <artifactId>mail</artifactId>
-            <version>1.4.5</version>
+            <version>1.5.0-b01</version>
         </dependency>
         <dependency>
             <groupId>javax.activation</groupId>




--
View this message in context: http://apache-commons.680414.n4.nabble.com/EMAIL-Using-Apache-Commons-Email-and-Google-tp743730p4665219.html
Sent from the Commons - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message