javax.mail.MessagingException: Exception reading response;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
You are trying to do an SSL connection to a non-SSL port. This will not work.
If you want to send mail through gmail, see the FAQ: http://java.sun.com/products/javamail/FAQ.html#gmail
If you don't want to use SSL, and you're using smtp instead of smtps try these settings
mail.smtp.starttls.enable=false
mail.transport.protocol=smtp
As Andersen answered, doing an SSL connection (mail.smtp.ssl.enable=true
) to a non-SSL port will throw this error.
This is commonly caused by connecting to the wrong port, as many popular mail services use port 587 instead of default smtps port 465. This applies to GMail, Hotmail/Live Mail, and Yahoo Mail.
My problem, however, is that Java Mail insists on using SSL even when I set ssl to false.
After tracing the source code, the problem is I used Session.getDefaultInstance, copied from some example code. It only creates a session with the given properties on the first call; subsequence calls will return that old session, instead of a new session.
Switching to Session.getInstance make sure it use the properties I pass in, and solved my "SSLException: Unrecognized SSL message".
I was getting the same exception when trying to send email via the Hotmail SMTP server at smtp.live.com. Here are the settings that worked for me in the end:
mail.smtp.starttls.enable=true
mail.smtp.port=587
I was facing this problem when using Gmail.
In order to use Gmail I had to turn ON "Allow less secure apps".
This Gmail setting can be found at https://www.google.com/settings/security/lesssecureapps after login the gmail account.