Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SMTP SSL, TLS and StartTLS

806322Oct 21 2010 — edited Oct 21 2010
Hi All,

In our application we will provide UI to specify SMTP server, port, username and password.
We will provide security options - None, SSL and TLS
I know what to do for None and SSL. There are lot of examples on the FAQ and forum.

I am confused about TLS.

1. Is the following all I need to do to connect to a server that supports TLS smtp?
props.put("mail.smtp.user", myemail);
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port","587");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
MimeMessage msg = new MimeMessage(session);
...
Transport.send(msg);
I tried this with gmail smpt and it did not work. I am not sure what I need to do if the server supports startTLS.

It will be nice if an example is included in the FAQ for gmail TLS

2. For SSL connection, when would you set
props.put("mail.smtp.starttls.enable","true");
For gmail smtp SSL, it works whether or not I set this.

3. Are there any servers that support StartTLS but not TLS?

4. Are there any other settings I should support besides None, SSL and TLS?

Thanks for your help,
Bindu
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 18 2010
Added on Oct 21 2010
3 comments
3,729 views