23
javax.mail.MessagingException: Exception reading response;
  nested exception is:
        javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
        at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1764)
        at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1523)
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:453)
        at javax.mail.Service.connect(Service.java:313)
        at javax.mail.Service.connect(Service.java:172)
        at javax.mail.Service.connect(Service.java:121)
        at javax.mail.Transport.send0(Transport.java:190)
        at javax.mail.Transport.send(Transport.java:120)
        at javaapplication5.SendMail.send(SendMail.java:77)
        at javaapplication5.SendMailTest.main(SendMailTest.java:17)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
        at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(InputRecord.java:523)
        at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:355)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:789)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1112)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:744)
        at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
        at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:106)
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
        at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
        at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:84)
        at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1742)
        ... 9 more

Can anybody help me to send a mail using JavaMail API using proxy?

3
  • 4
    I think it would be helpful if you post the code you're using to send the mail :D Commented Jul 21, 2009 at 6:42
  • What is the code that throws this exception? Commented Jul 21, 2009 at 6:42
  • 1
    How about some code that produces this Stacktrace? Commented Jul 21, 2009 at 6:42

5 Answers 5

15

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

Sign up to request clarification or add additional context in comments.

Comments

7

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

Comments

3

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

Comments

2

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".

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.