When connecting to an SMTP server using javax.mail
, how can I make sure that the version of TLS is v1.2 or higher.
I am using Java version 8 (update 162).
Enter the URL you wish to check in the browser. Right-click the page or select the Page drop-down menu, and select Properties. In the new window, look for the Connection section. This will describe the version of TLS or SSL used.
To ensure the TLS version used:
props.put("mail.smtp.ssl.protocols", "TLSv1.2");
I don't have the means to 100% confirm that I am connecting with v1.2 but this is what I found. How to force JavaMailSenderImpl to use TLS1.2?
You can use the following snippet to get a space delimited list of the supported protocols:
String.join(" ", SSLContext.getDefault().getSupportedSSLParameters().getProtocols());
In Java 8 that would return a list with TLSv1.2
as the highest version and a list with TLSv1.3
as the highest version in Java 11.
Then simply set the System property mail.smtp.ssl.protocols
to that value, e.g.
String protocols = String.join(" ",
SSLContext
.getDefault()
.getSupportedSSLParameters()
.getProtocols()
);
System.setProperty("mail.smtp.ssl.protocols", protocols);
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