Unable to send an email using SMTP (Getting javax.mail.MessagingException: Could not convert socket to TLS;)

前端 未结 11 1882
北恋
北恋 2020-12-10 12:04

I have written the following code for sending email using javamail API through SMTP as TLS as SSL is not supported but I ended up with the following exception. Please see my

相关标签:
11条回答
  • 2020-12-10 12:39

    I had this problem. the reason was our administrator had blocked TLS and SSL protocols.

    0 讨论(0)
  • 2020-12-10 12:40

    Maybe this issue related to security and smtp.ssl is not trusted that's why issue occurs.

    I resolve this issue just add a property

    spring.mail.properties.mail.smtp.ssl.trust=smtp.gmail.com
    

    Now it is working fine for me.

    0 讨论(0)
  • 2020-12-10 12:42

    Commenting-out the property mail.smtp.starttls.enable means you fall back to a default and unsecured connection, which would work only if the remote SMTP host also accepts unsecured transport on port 587 (the port for mail submission versus port 25 for end-delivery or relay operations).

    In my context, TLS is compulsory on 587 and any attempt to open a session without TLS yield the SMTP server error response 530 Must issue a STARTTLS command first.

    Then setting mail.smtp.starttls.enable to true alone still yield the same error Could not convert socket to TLS but now with a clue: Server is not trusted. Indeed, you must have either a keystore defined in the JVM start properties that would contain a certificate chain ending onto a trusted root certificate, either enforce trust with this extra property: mail.smtp.ssl.trust set to the remote host name.

    Configuring the whole stuff in Spring support for javamail for instance (which you can easily map to plain javamail API) requires all of the following:

    <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="host" value="theRemoteSmtpServer" />
    <property name="port" value="587" />
    <property name="username" value="muUserID" />
    <property name="password" value="myPassword" />
    <property name="javaMailProperties">
        <props>
            <prop key="mail.smtp.starttls.enable">true</prop>
            <prop key="mail.smtp.ssl.trust">theRemoteSmtpServer</prop>
            <prop key="mail.smtp.auth">true</prop>
        </props>
    </property>
    </bean>
    
    0 讨论(0)
  • 2020-12-10 12:47

    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)
  • 2020-12-10 12:48

    It looks like the SSL implementation used by your server is not compatible with the SSL implementation in the version of the JDK you're using. The file SSLNOTES.txt (also included in the JavaMail download bundle) has some debugging tips. You might need a JDK SSL expert to sort this out.

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