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

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");
												

I can resolve the problem replacing java-mail 1.4. with java-mail 1.6.2 .

Similar problem
https://jira.atlassian.com/browse/FE-7294

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!

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");
												

Hello, here is all properties i'm using;

Properties props = new Properties();
props.put("mail.smtp.socketFactory.fallback", "false");  
props.put("mail.smtp.quitwait", "false");
props.put("mail.smtp.socketFactory.port", "587");  
props.put("mail.host", smtp.office365.com);
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.smtp.port", "587");
props.setProperty("mail.smtp.ssl.trust", "*");
props.setProperty("mail.smtp.starttls.enable", String.valueOf(requireTls));//True or False
props.setProperty("mail.smtp.ssl.protocols", "TLSv1.2");
props.setProperty("mail.smtp.timeout", "300000");
props.setProperty("mail.smtp.connectiontimeout", "300000");
props.setProperty("mail.smtp.writetimeout", "300000");

But it seems that you are catching another exception. In your case, it's trying to connect with localhost port 25, check your properties.