1

I just switched to Java 11 from Java 10 and start getting below exception when I try to send an email:

javax.mail.MessagingException: Could not convert socket to TLS
    at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:2155) ~[xxx-0.40.0-SNAPSHOT.jar:?]
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:752) ~[xxx-0.40.0-SNAPSHOT.jar:?]
    at javax.mail.Service.connect(Service.java:366) ~[xxx-0.40.0-SNAPSHOT.jar:?]
    at javax.mail.Service.connect(Service.java:246) ~[xxx-0.40.0-SNAPSHOT.jar:?]
    at cc.blynk.server.notifications.mail.ThirdPartyMailClient.send(ThirdPartyMailClient.java:73) ~[xxx-0.40.0-SNAPSHOT.jar:?]
    at cc.blynk.server.notifications.mail.ThirdPartyMailClient.sendHtml(ThirdPartyMailClient.java:62) ~[xxx-0.40.0-SNAPSHOT.jar:?]
    at cc.blynk.server.notifications.mail.MailWrapper.sendHtml(MailWrapper.java:47) ~[xxx-0.40.0-SNAPSHOT.jar:?]
    at cc.blynk.server.web.handlers.logic.organization.users.WebInviteUserLogic.lambda$messageReceived$0(WebInviteUserLogic.java:111) ~[xxx-0.40.0-SNAPSHOT.jar:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?]
    at java.lang.Thread.run(Thread.java:834) ~[?:?]
Caused by: java.io.IOException: Server is not trusted: smtp.gmail.com
    at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:632) ~[xxx-0.40.0-SNAPSHOT.jar:?]
    at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:547) ~[xxx-0.40.0-SNAPSHOT.jar:?]
    at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:2150) ~[xxx-0.40.0-SNAPSHOT.jar:?]
    ... 10 more

This code was working just fine on the prev version of Java:

java version "10.0.2" 2018-07-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)

New Java version:

java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)

I found similar questions and fixed above error with:

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

property in my mail.properties. However, I would like to understand why this error happens only in Java 11? I think this has something to do with removed javax.mail module from java. Am I right?

This is my dependencies:

<javax.mail.version>1.6.1</javax.mail.version>
<javax.activation.version>1.2.0</javax.activation.version>

<dependency>
    <groupId>com.sun.mail</groupId>
    <artifactId>javax.mail</artifactId>
    <version>${javax.mail.version}</version>
    <exclusions>
        <exclusion>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>com.sun.activation</groupId>
    <artifactId>javax.activation</artifactId>
    <version>${javax.activation.version}</version>
</dependency>
Dmitriy Dumanskiy
  • 11,657
  • 9
  • 37
  • 57
  • Could possibly be because of [TLS 1.3 implementation](http://openjdk.java.net/jeps/332) brought in. You can try and place a debug point at *L:2150* of `SMTPTransport.startTLS` and see the difference in both. Looks to me the underlying implementation difference could be visible possibly at `SocketFetcher` class of the module/library. – Naman Oct 31 '18 at 10:22
  • 1
    Possibly this can help https://stackoverflow.com/questions/52830481/java-11-chrome-firefox-tls-decrypt-error – Mikhail Kholodkov Oct 31 '18 at 12:38

0 Answers0