This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes Confusion over SSL and TLS for sending mail thorugh JAVA Mail API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Confusion over SSL and TLS for sending mail thorugh JAVA Mail API" Watch "Confusion over SSL and TLS for sending mail thorugh JAVA Mail API" New topic
Author

Confusion over SSL and TLS for sending mail thorugh JAVA Mail API

nikhil jai
Greenhorn

Joined: Aug 07, 2008
Posts: 9
Hi ,
I dont have much idea about SSL/TLS so please correct me if I have put anything wrong . I am working on sending alert mails using JAVA Mail API using SMTP protocol . The mail server can be anything like gmail ,hotmail etc.

Now gmail and hotmail works over secure layer . From the net and the examples I have tried , I have found that HOTMAIL works only over TLS , SSL cant't be used for hotmail. While GMAIL works both over SSL and TLS

i.e for HOTMAIL only the following property setting works :-

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties props = new Properties();
props.put("mail.host","smtp.live.com");
props.put("mail.smtp.port", 587);
props.put("mail.smtp.auth", "true");



While for Gmail both sets of configuration works :-

1) Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties props = new Properties();
props.put("mail.host","smtp.gmail.com");
props.put("mail.smtp.port", 587);
props.put("mail.smtp.auth", "true");

2)
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties props = new Properties();
props.put("mail.host","smtp.gmail.com");
props.put("mail.smtp.port", 465);
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.quitwait", "false");
props.put("mail.smtp.auth", "true");

Note the port has to be 587 in first set of configuration and 465 in second .

So I have the following doubts in my mind

1) I have read that TLS is a newer version of SSL but they are almost similar . What is exactly the difference between TLS and SSL . When specific cases each will be used (examples will be appreciated) .
2 ) Are all those mail servers which requires SSL autentication , will work with TLS .i.e like GMAIL ,all those servers which require SSL authentication ,the first set of configuration will work always ?
3) I have come across this post -> http://stackoverflow.com/questions/411331/using-javamail-with-tls which says :-

"props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

is mandatory if the SMTP server uses SSL Authentication, like the GMail SMTP server does. However if the server uses Plaintext Authentication over TLS, it should not be present, because Java Mail will complain about the initial connection being plaintext. "

What is "Plaintext Authentication over TLS" and how is it different from SSL authentication ?

Thanks in advance






nikhil jai
Greenhorn

Joined: Aug 07, 2008
Posts: 9
Hey ,
In my first post I forgot to specify the following property for hotmail and gmail first set of configuration to start TLS

props.put("mail.smtp.starttls.enable","true");

So for hotmail the properties are :-

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties props = new Properties();
props.put("mail.host","smtp.live.com");
props.put("mail.smtp.port", 587);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable","true");

and for gmail the first set of configuration is :-
1) Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties props = new Properties();
props.put("mail.host","smtp.gmail.com");
props.put("mail.smtp.port", 587);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable","true");
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42371
    
  64
See http://java.sun.com/products/javamail/FAQ.html#gmail, and pay close attention to the details of all the properties.


Ping & DNS - my free Android networking tools app
nikhil jai
Greenhorn

Joined: Aug 07, 2008
Posts: 9
Hi Ulf ,
Thanks for your reply but actually I have already gone through this link .And whatever properties I have pasted here is only after testing . So could you please reply specifically to the questions I asked .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Confusion over SSL and TLS for sending mail thorugh JAVA Mail API