You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Stefano \"Kismet\" Lenzi" <ki...@gmail.com> on 2009/11/16 15:43:49 UTC

[EMAIL] Using Apache Commons Email and Google

Dear All,

I was trying to use the Commons Email project for sending email with
the Google provider, but I failed. I tried with the following code
		SimpleEmail email = new SimpleEmail();
		email.setDebug(true);
		email.addTo(MAIL_DESTINATION, "Stefano Lenzi");
		email.setFrom(MAIL_SENDER, "Test");
		email.setSubject("Test message");
		email.setMsg("This is a simple test of commons-email");
		email.setHostName(SMTP_HOST_NAME);
		email.setAuthentication(SMTP_AUTH_USER, SMTP_AUTH_PWD);
		email.setTLS(true);
		email.setSmtpPort(SMTP_HOST_PORT);
		email.send();
but nothing happened. Here is the debug shown DEBUG: JavaMail version
1.4.1ea-SNAPSHOT
DEBUG: not loading file: C:\Programmi\Java\jre6\lib\javamail.providers
DEBUG: java.io.FileNotFoundException:
C:\Programmi\Java\jre6\lib\javamail.providers (Impossibile trovare il
file specificato)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name:
{com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun
Microsystems, Inc],
com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
Microsystems, Inc],
com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun
Microsystems, Inc],
com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun
Microsystems, Inc],
com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun
Microsystems, Inc],
com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun
Microsystems, Inc]}
DEBUG: Providers Listed By Protocol:
{imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun
Microsystems, Inc],
imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun
Microsystems, Inc],
smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun
Microsystems, Inc],
pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun
Microsystems, Inc],
pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun
Microsystems, Inc],
smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: not loading file: C:\Programmi\Java\jre6\lib\javamail.address.map
DEBUG: java.io.FileNotFoundException:
C:\Programmi\Java\jre6\lib\javamail.address.map (Impossibile trovare
il file specificato)
DEBUG: getProvider() returning
javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false

I believe that the problem is that the protocol chosen is "smtp" while
it should be "smpts". In fact, I have later tryed the code available
here:
http://www.rgagnon.com/javadetails/java-0570.html
the it worked perfectly, and the two difference are the protocol
chosen for sending the email and the way the transport is initialized.

Is it a bug in Commons Email, or am I doing something wrong?

Ciao,
Stefano Lenzi

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


Re: [EMAIL] Using Apache Commons Email and Google

Posted by Thomas Neidhart <th...@gmail.com>.
On 07/09/2014 02:57 AM, Jason wrote:
> 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.

Hi Jason,

thanks for the hint, but are you sure that this is working correctly?

Looking at the Transport.send(Message msg, Address[] addresses) javadoc,
it states the following:

  * Send the message to the specified addresses, ignoring any
  * recipients specified in the message itself.

Thus when calling it with the from address, it will only be sent to the
originator of the message and not to the actual recipients.

Furthermore, the code does not compile as there is no overloaded send
method which takes a String as third argument (and there is no implicit
conversion to an Address).

Thomas

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


Re: [EMAIL] Using Apache Commons Email and Google

Posted by Jason <ja...@plutext.org>.
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


Re: [EMAIL] Using Apache Commons Email and Google

Posted by Petite Abeille <pe...@mac.com>.
On Nov 16, 2009, at 4:45 PM, Christopher Schultz wrote:

> STARTTLS-over-SMTP will give you better performance, because only the
> authentication is encrypted and not the entire SMTP conversation.

Hmm... are you sure? 

AFAIK, STARTTLS promotes a plain connection to an encrypted one, irrespectively of any authentication mechanisms:

http://en.wikipedia.org/wiki/STARTTLS

Once a connection is upgraded, it stays encrypted. 

Perhaps you are referring to SASL, which deals with authentication?

One way or another, way too many acronyms :D

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


Re: [EMAIL] Using Apache Commons Email and Google

Posted by Siegfried Goeschl <si...@it20one.at>.
Hi folks,

see my comments below ...

Cheers,

Siegfried Goeschl

Stefano "Kismet" Lenzi wrote:
> On Mon, Nov 16, 2009 at 16:45, Christopher Schultz
> <ch...@christopherschultz.net> wrote:
>   
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Stephano,
>>
>> On 11/16/2009 9:43 AM, Stefano "Kismet" Lenzi wrote:
>>     
>>> I was trying to use the Commons Email project for sending email with
>>> the Google provider, but I failed. I tried with the following code
>>>               SimpleEmail email = new SimpleEmail();
>>>               email.setDebug(true);
>>>               email.addTo(MAIL_DESTINATION, "Stefano Lenzi");
>>>               email.setFrom(MAIL_SENDER, "Test");
>>>               email.setSubject("Test message");
>>>               email.setMsg("This is a simple test of commons-email");
>>>               email.setHostName(SMTP_HOST_NAME);
>>>               email.setAuthentication(SMTP_AUTH_USER, SMTP_AUTH_PWD);
>>>               email.setTLS(true);
>>>               email.setSmtpPort(SMTP_HOST_PORT);
>>>               email.send();
>>> but nothing happened.
>>>       
>> Try setting -Dmail.debug=true and run it again. This will give you much
>> more output from Javamail.
>>     
>
> I have tried to set the option but the output didn't change
>
>   
[SG] you already enabled the debug mode using email.setDebug()
>> It's unclear from the javadoc, but it's possible that setTLS(true)
>> merely configures Javamail to use STARTTLS over a plaintext SMTP
>> connection. If you want to use SMTPS, try setting
>> - -Dmail.transport.protocol=smtps to see if that helps.
>>     
>
> Even the -Dmail.transport.protocol=smtps  system property didn't
> change anything, it looks like that the system properties are not used
> by Commons Email
>   
[SG] correct - all the required properties are set within commons-email
thereby not relying on system properties.
>   
>>> DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
>>>       
>> See that SSL=false. If you want SSL, use setSSL(true) instead of
>> setTLS(true).
>>     
>
> I don't know why I haven't tried it before, but I'm glad to say that
> it worked :)
> It's strange that the first lines of the output didn't change
>   
[SG] Should provide some Q&A covering connectivity to GMAIL
> DEBUG: JavaMail version 1.4.1ea-SNAPSHOT
> DEBUG: not loading file: C:\Programmi\Java\jre6\lib\javamail.providers
> DEBUG: java.io.FileNotFoundException:
> C:\Programmi\Java\jre6\lib\javamail.providers (Impossibile trovare il
> file specificato)
> DEBUG: !anyLoaded
> DEBUG: not loading resource: /META-INF/javamail.providers
> DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
> DEBUG: Tables of loaded providers
> DEBUG: Providers Listed By Class Name:
> {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun
> Microsystems, Inc],
> com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
> Microsystems, Inc],
> com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun
> Microsystems, Inc],
> com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun
> Microsystems, Inc],
> com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun
> Microsystems, Inc],
> com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun
> Microsystems, Inc]}
> DEBUG: Providers Listed By Protocol:
> {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun
> Microsystems, Inc],
> imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun
> Microsystems, Inc],
> smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun
> Microsystems, Inc],
> pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun
> Microsystems, Inc],
> pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun
> Microsystems, Inc],
> smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
> Microsystems, Inc]}
> DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
> DEBUG: !anyLoaded
> DEBUG: not loading resource: /META-INF/javamail.address.map
> DEBUG: not loading file: C:\Programmi\Java\jre6\lib\javamail.address.map
> DEBUG: java.io.FileNotFoundException:
> C:\Programmi\Java\jre6\lib\javamail.address.map (Impossibile trovare
> il file specificato)
> DEBUG: getProvider() returning
> javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
> Microsystems, Inc]
> DEBUG SMTP: useEhlo true, useAuth true
> DEBUG SMTP: useEhlo true, useAuth true
> DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
> 220 mx.google.com ESMTP 3sm5919994fge.24
> DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
>
> In particular, the lines:
> "DEBUG: getProvider() returning
> javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
> Microsystems, Inc]"
> "DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false"
>
>   
>> I'm not sure what gmail prefers and/or requires, but generally
>> STARTTLS-over-SMTP will give you better performance, because only the
>> authentication is encrypted and not the entire SMTP conversation.
>>
>>     
>>> http://www.rgagnon.com/javadetails/java-0570.html
>>>       
>> That page indicates that GMail requires SSL, not TLS. Try changing
>> setTLS(true) to setSSL(true) and see if that works.
>>     
[SG] thanks for the link
>> Hope that helps,
>> - -chris
>>     
>
> Thank you it helped!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>
>
>   

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


Re: [EMAIL] Using Apache Commons Email and Google

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stefano,

On 11/16/2009 1:27 PM, Stefano "Kismet" Lenzi wrote:
> On Mon, Nov 16, 2009 at 16:45, Christopher Schultz
> <ch...@christopherschultz.net> wrote:
>>
>> Try setting -Dmail.debug=true and run it again. This will give you much
>> more output from Javamail.
> 
> I have tried to set the option but the output didn't change

Hmm... that's strange. I thought javamail would read system properties
as well as those set directly using a java.util.Properties object, but
maybe it doesn't. Commons-email doesn't appear to give you the option of
setting javamail properties directly, but it does allow you to set the
javamail session like this:

Properties props = new Properties();
props.put("mail.transport.protocol", "smtps");
...

Session session = Session.getDefaultInstance(props);

...
email.setMailSession(session);
email.send();

This should allow you to set properties such as mail.debug,
mail.transport.protocol, etc.

>>> DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
>>
>> See that SSL=false. If you want SSL, use setSSL(true) instead of
>> setTLS(true).
> 
> I don't know why I haven't tried it before, but I'm glad to say that
> it worked :)

Glad to help.

> In particular, the lines:
> "DEBUG: getProvider() returning
> javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
> Microsystems, Inc]"

I don't find anything strange about the above log message, do you?

> "DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false"

Now /that/ is strange if you have set SSL=true. Perhaps there's a bug in
the debug logging.

I have found that commons-email acts strangely in a number of
circumstances. I unfortunately had to abandon its use a while back in
order to be able to send attachments along with text *and* HTML email
messages. I wrote my own wrapper with what I believe is a simpler API.
You are welcome to it: http://www.christopherschultz.net/projects/java/

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksBw5IACgkQ9CaO5/Lv0PAkTgCffhkbKXQCSp1y5UB4XfOnBi5x
NRgAoJQtnIbh60dVUlXIh78tux/mY2+6
=4S7Y
-----END PGP SIGNATURE-----

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


Re: [EMAIL] Using Apache Commons Email and Google

Posted by "Stefano \"Kismet\" Lenzi" <ki...@gmail.com>.
On Mon, Nov 16, 2009 at 16:45, Christopher Schultz
<ch...@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Stephano,
>
> On 11/16/2009 9:43 AM, Stefano "Kismet" Lenzi wrote:
>> I was trying to use the Commons Email project for sending email with
>> the Google provider, but I failed. I tried with the following code
>>               SimpleEmail email = new SimpleEmail();
>>               email.setDebug(true);
>>               email.addTo(MAIL_DESTINATION, "Stefano Lenzi");
>>               email.setFrom(MAIL_SENDER, "Test");
>>               email.setSubject("Test message");
>>               email.setMsg("This is a simple test of commons-email");
>>               email.setHostName(SMTP_HOST_NAME);
>>               email.setAuthentication(SMTP_AUTH_USER, SMTP_AUTH_PWD);
>>               email.setTLS(true);
>>               email.setSmtpPort(SMTP_HOST_PORT);
>>               email.send();
>> but nothing happened.
>
> Try setting -Dmail.debug=true and run it again. This will give you much
> more output from Javamail.

I have tried to set the option but the output didn't change

>
> It's unclear from the javadoc, but it's possible that setTLS(true)
> merely configures Javamail to use STARTTLS over a plaintext SMTP
> connection. If you want to use SMTPS, try setting
> - -Dmail.transport.protocol=smtps to see if that helps.

Even the -Dmail.transport.protocol=smtps  system property didn't
change anything, it looks like that the system properties are not used
by Commons Email

>
>> DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
>
> See that SSL=false. If you want SSL, use setSSL(true) instead of
> setTLS(true).

I don't know why I haven't tried it before, but I'm glad to say that
it worked :)
It's strange that the first lines of the output didn't change

DEBUG: JavaMail version 1.4.1ea-SNAPSHOT
DEBUG: not loading file: C:\Programmi\Java\jre6\lib\javamail.providers
DEBUG: java.io.FileNotFoundException:
C:\Programmi\Java\jre6\lib\javamail.providers (Impossibile trovare il
file specificato)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name:
{com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun
Microsystems, Inc],
com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
Microsystems, Inc],
com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun
Microsystems, Inc],
com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun
Microsystems, Inc],
com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun
Microsystems, Inc],
com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun
Microsystems, Inc]}
DEBUG: Providers Listed By Protocol:
{imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun
Microsystems, Inc],
imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun
Microsystems, Inc],
smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun
Microsystems, Inc],
pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun
Microsystems, Inc],
pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun
Microsystems, Inc],
smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: not loading file: C:\Programmi\Java\jre6\lib\javamail.address.map
DEBUG: java.io.FileNotFoundException:
C:\Programmi\Java\jre6\lib\javamail.address.map (Impossibile trovare
il file specificato)
DEBUG: getProvider() returning
javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
220 mx.google.com ESMTP 3sm5919994fge.24
DEBUG SMTP: connected to host "smtp.gmail.com", port: 465

In particular, the lines:
"DEBUG: getProvider() returning
javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
Microsystems, Inc]"
"DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false"

>
> I'm not sure what gmail prefers and/or requires, but generally
> STARTTLS-over-SMTP will give you better performance, because only the
> authentication is encrypted and not the entire SMTP conversation.
>
>> http://www.rgagnon.com/javadetails/java-0570.html
>
> That page indicates that GMail requires SSL, not TLS. Try changing
> setTLS(true) to setSSL(true) and see if that works.
>
> Hope that helps,
> - -chris

Thank you it helped!

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


Re: [EMAIL] Using Apache Commons Email and Google

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stephano,

On 11/16/2009 9:43 AM, Stefano "Kismet" Lenzi wrote:
> I was trying to use the Commons Email project for sending email with
> the Google provider, but I failed. I tried with the following code
> 		SimpleEmail email = new SimpleEmail();
> 		email.setDebug(true);
> 		email.addTo(MAIL_DESTINATION, "Stefano Lenzi");
> 		email.setFrom(MAIL_SENDER, "Test");
> 		email.setSubject("Test message");
> 		email.setMsg("This is a simple test of commons-email");
> 		email.setHostName(SMTP_HOST_NAME);
> 		email.setAuthentication(SMTP_AUTH_USER, SMTP_AUTH_PWD);
> 		email.setTLS(true);
> 		email.setSmtpPort(SMTP_HOST_PORT);
> 		email.send();
> but nothing happened.

Try setting -Dmail.debug=true and run it again. This will give you much
more output from Javamail.

It's unclear from the javadoc, but it's possible that setTLS(true)
merely configures Javamail to use STARTTLS over a plaintext SMTP
connection. If you want to use SMTPS, try setting
- -Dmail.transport.protocol=smtps to see if that helps.

> DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false

See that SSL=false. If you want SSL, use setSSL(true) instead of
setTLS(true).

I'm not sure what gmail prefers and/or requires, but generally
STARTTLS-over-SMTP will give you better performance, because only the
authentication is encrypted and not the entire SMTP conversation.

> http://www.rgagnon.com/javadetails/java-0570.html

That page indicates that GMail requires SSL, not TLS. Try changing
setTLS(true) to setSSL(true) and see if that works.

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksBc6wACgkQ9CaO5/Lv0PCC9gCdEyCUKnv8znCnuL3hvLcv/Bp+
CzoAoJA2vp9VPQHzATxRgD3SUe3J86tW
=mQy/
-----END PGP SIGNATURE-----

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