Personal tools

Oct 28, 2011

Using JavaMail with TLS

Snippets about sending mail though Java with TLS support

Here is an example to show you how to use JavaMail API method to send an email, using both TLS and SSL connection.

If you are using TLS, remember to disable this property:

props.put("mail.smtp.socketFactory.class", "");


and enable


These are the complete properties to set: 
props.put("", server);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.socketFactory.port", port);
props.put("mail.smtp.socketFactory.fallback", "false");


Remember that, when you set Authentication to server with PasswordAuthentication class, you could experience this error:

"javax.mail.AuthenticationFailedException: 535-5.7.1 Username and Password not accepted."

Send by server if user or password used for authentication failed. Usually means that server requires full user name ( to be used.

Filed under:
comments powered by Disqus