I have a Problem sending Mails with Javax. We used gmail for about 4 years to send mails from our Java Software. Now i get the following Error:
Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
at SendEmail.sendMissingMailWeek(SendEmail.java:233)
at main.negVerkaeufeMailenWeek(main.java:368)
at main.main(main.java:79)
Caused by: javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1907)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:666)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at SendEmail.sendMissingMailWeek(SendEmail.java:226)
... 2 more
Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
at sun.security.ssl.HandshakeContext.<init>(HandshakeContext.java:171)
at sun.security.ssl.ClientHandshakeContext.<init>(ClientHandshakeContext.java:98)
at sun.security.ssl.TransportContext.kickstart(TransportContext.java:220)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:428)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:549)
at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:486)
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1902)
... 9 more
Process finished with exit code 1
These are my Settings for gmail:
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
props.put("mail.smtp.debug", "true");
I also tried other Mailserver (O365, Strato) but got the same Error.
The error indicates some problem related to the TLS protocol required for establishing a secure connection with the mail servers.
As you can see in the questions comments, the problem can be caused by a lot of different things. Without knowing your OS, JDK and JavaMail library versions we can only guest the true reason.
@g00se gives you a good advice: please, try running your program with SSL debugging enabled by providing the following option:
-Djavax.net.debug=all
In addition, try including explicitly the TLS protocol in your configuration properties, it may be of help:
props.put("mail.smtp.ssl.protocols", "TLSv1.2");
In any way, for the symptoms you indicated, and due to the fact that AFAIK Google has not changed any related configuration recently, probably your problem will be related with a change introduced in the JDK distributions in order to disable by default insecure TLS protocol versions:
security-libs/javax.net.ssl
➜ Disable TLS 1.0 and 1.1TLS 1.0 and 1.1 are versions of the TLS protocol that are no longer considered secure and have been superseded by more secure and modern versions (TLS 1.2 and 1.3).
These versions have now been disabled by default. If you encounter issues, you can, at your own risk, re-enable the versions by removing "TLSv1" and/or "TLSv1.1" from the
jdk.tls.disabledAlgorithms
security property in thejava.security
configuration file.
As you can see in the bug description, the change has been backported to different JDK versions.
Perhaps you upgraded your JDK and the problem raised.
If that is the case, as indicated in the quote, try editing your java.security
configuration file and remove TLSv1
and/or TLSv1.1
from the jdk.tls.disabledAlgorithms
security property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With