javax.net.ssl.SSLException when sending mail using JavaMail

前端 未结 5 1938
走了就别回头了
走了就别回头了 2021-01-01 12:12
javax.mail.MessagingException: Exception reading response;
  nested exception is:
        javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?         


        
相关标签:
5条回答
  • 2021-01-01 12:30

    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

    0 讨论(0)
  • 2021-01-01 12:30

    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
    
    0 讨论(0)
  • 2021-01-01 12:34

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

    0 讨论(0)
  • 2021-01-01 12:49

    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
    
    0 讨论(0)
  • 2021-01-01 12:49

    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.

    0 讨论(0)
提交回复
热议问题