title: javax.net.ssl.SSLHandshakeException:No appropriate protocol. How to force Java to use TLSv1.2 for sending mail?
body: <p>I am trying to use JavaMailSender to send mails in spring boot, but I am getting this error:</p>
  <pre><code>javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate). Failed messages: 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)
  </code></pre>
  <p>After doing some reading, I found it is because we are using TLSv1 or TLSv1.1 which is outdated, and we should use v1.2 or higher. I tried to add ssl.protocols property in application.yml with value TLSv1.2, but it does not seem to work. Here is my application.yml:</p>
  <pre><code>spring:
    mail:
      host: smtp.gmail.com
      port: 587
      username: ******@gmail.com
      password: *******
      protocol: smtp
      tls: true
      properties.mail.smtp:
        auth: true
        ssl.trust: smtp.gmail.com
        starttls.required: true
        starttls.enabled: true
        ssl.protocols: TLSv1.2
  </code></pre>
  <p>and here is the method that sends the mail:</p>
  <pre><code>public void sendEmail(String to, String subject, String body) {
      logger.info(&quot;Sending mail to : &quot; + to);
      SimpleMailMessage mail = new SimpleMailMessage();
      mail.setTo(to);
      mail.setSubject(subject);
      mail.setText(body);
  
      try {
          javaMailSender.send(mail);
          logger.info(&quot;Mail sent to &quot; + to);
      } catch (Exception e) {
          logger.error(&quot;Could not send mail to &quot; + to + &quot;. Exception : &quot; + e.getMessage());
      }
  }
  </code></pre>
  <p>I updated JavaMailSender version but it didn't fix the issue. The only thing that worked was removing TLSv1 and TLSv1.1 from jdk.tls.disabledAlgorithms as suggested in <a href="https://stackoverflow.com/a/68238768/8198017">this answer</a>, but it is only a temporary fix. How can make the mail sender use TLSv1.2 or higher? Is there anything wrong in the way I am defining the ssl.protocols property in application.yml?</p>
  <p>This is the java version I am using:</p>
  <pre><code>openjdk version &quot;1.8.0_292&quot;
  OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_292-b10)
  OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.292-b10, mixed mode)
  </code></pre>
  <p>and the spring boot starter mail version:</p>
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-mail&lt;/artifactId&gt;
      &lt;version&gt;2.5.3&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>