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).
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).
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);
© 2022 - 2024 — McMap. All rights reserved.