Share via

javax.mail.MessagingException: Could not convert socket to TLS

Archish S 16 Reputation points
May 4, 2021, 5:21 AM

I'm trying to connect to outlook server from my java app to send outgoing mail, but fails insatiately. getting the error below.

What's the SOLUTION ?

javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
javax.net.ssl.SSLHandshakeException: Remote host terminated the handshake
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1999)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:709)
at javax.mail.Service.connect(Service.java:386)
at javax.mail.Service.connect(Service.java:245)
at javax.mail.Service.connect(Service.java:194)
at javax.mail.Transport.send0(Transport.java:253)
at javax.mail.Transport.send(Transport.java:124)
at com.stupa.domain.EmailUtil.sendEmail(EmailUtil.java:66)
at com.stupa.domain.SendMail.sendMail(SendMail.java:48)
at com.stupa.dao.TicketSLADaoImpl.getITCDailyCallsStatusReport(TicketSLADaoImpl.java:17309)
at com.stupa.controller.SLAScheduleControlller.sendTCSITCTicketsReport(SLAScheduleControlller.java:100)
at com.stupa.domain.Task.runTCSReportTask(Task.java:119)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: javax.net.ssl.SSLHandshakeException: Remote host terminated the handshake
at sun.security.ssl.SSLSocketImpl.handleEOF(SSLSocketImpl.java:1310)
at sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1151)
at sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1054)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:394)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:543)
at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:480)
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1994)
... 25 more
Caused by: java.io.EOFException: SSL peer shut down incorrectly
at sun.security.ssl.SSLSocketInputRecord.decode(SSLSocketInputRecord.java:167)
at sun.security.ssl.SSLTransport.decode(SSLTransport.java:108)
at sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1143)
... 30 more

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
1,013 questions
{count} votes

7 answers

Sort by: Most helpful
  1. Felipe Santolin 46 Reputation points
    Oct 28, 2021, 11:27 AM

    Hi, i had the same problem, resolved with the following properties in my code, in runtime, and only worked putting at the code

        Properties props = new Properties();
        props.setProperty("mail.smtp.starttls.enable", "true");
        props.setProperty("mail.smtp.ssl.protocols", "TLSv1.2");
    
    6 people found this answer helpful.

  2. Vladimir Reznitsky 11 Reputation points
    Oct 11, 2021, 12:20 PM

    Similar issue is occurring in our system during last 2 weeks. Fraction of failed requests is growing each day and reached 25%. No help from Microsoft support, they do not acknowledge the problem. Very frustrating.

    2 people found this answer helpful.

  3. Carlos López Pérez 6 Reputation points
    Oct 11, 2021, 10:43 AM

    I have the same problem with openjdk 8 (131 and 302 revisions)


  4. Brian 1 Reputation point
    Feb 16, 2022, 4:08 PM

    Hello,

    I see this is working for some. What other Properties did you need to set? I am still receiving the following exception

    Exception in thread "main" com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1;
    nested exception is:
    java.net.ConnectException: Connection refused: connect

    Here the Properties I am using

    Properties props;
    props = new Properties();
    props.put("smtp.office365.com", "587");
    props.put("mail.smtp.auth", true);
    props.put("mail.smtp.starttls.enable", true);
    props.setProperty("mail.smtp.ssl.protocols", "TLSv1.2");

    Any feedback would be appreciated and helpful. Thanks!

    0 comments No comments

  5. Brian 1 Reputation point
    Feb 16, 2022, 4:29 PM

    Helps when you set them properly...ughhhh :-\

        Properties props = new Properties();        
        props.put("mail.smtp.host", "smtp.office365.com");
        props.put("mail.smtp.post", "587");
        props.put("mail.smtp.auth", true);
        props.put("mail.smtp.starttls.enable", true);
        props.put("mail.smtp.ssl.protocols", "TLSv1.2");
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.