How to verify the TLS version used in javax.mail.*;
Asked Answered
T

2

8

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).

Tracy answered 5/6, 2018 at 19:5 Comment(2)
What version of Java are you using?Ap
@JohnHorman I am using v8 (update 162). I updated my original post.Tracy
T
7

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?

Tracy answered 5/6, 2018 at 20:28 Comment(1)
if you send the mail to your google account or Microsoft account and go into send items in Gmail and check the option "show original" and if office 365 move sent items to other folder and check option view > view message details. you will found 'TLS1_2'Erudite
T
3

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);
Tentacle answered 24/8, 2019 at 1:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.