如何强制 JavaMailSenderImpl 使用 TLS1.2?

2023-10-14Java开发问题
10

本文介绍了如何强制 JavaMailSenderImpl 使用 TLS1.2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

有一个在 Tomcat 上运行的 JDK7 应用程序,它确实具有以下环境设置:

Have a JDK7 app running on Tomcat and it does have the following env settings:

-Dhttps.protocols=TLSv1.1,TLSv1.2 

上述设置确保我们在通过 HTTPS 连接时不使用 TLS 1.0,同时进行 API 调用等.

The above setting ensures that we don't use TLS 1.0 when connecting over HTTPS while making API calls etc.

我们还使用 org.springframework.mail.javamail.JavaMailSenderImpl 类来发送外发 SMTP 电子邮件,并使用这些道具:

We also use the org.springframework.mail.javamail.JavaMailSenderImpl class to send outgoing SMTP email, and use these props:

 mail.smtp.auth=false;mail.smtp.socketFactory.port=2525;mail.smtp.socketFactory.fallback=true;mail.smtp.starttls.enable=true

问题在于升级到 TLS1.2 时与 SMTP 电子邮件服务器的连接失败.

The problem is that the connection to the SMTP email server is failing when it's upgraded to TLS1.2.

javax.net.ssl.SSLHandshakeException:远程主机关闭连接握手时

javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

是否存在强制使用 TLS1.2 协议的设置或代码更改?

我做了一些搜索,看起来这些环境设置仅适用于小程序和 Web 客户端,不适用于服务器端应用程序

I did some searching and it looks like these env settings are only for applet and web clients, not for server side apps

-Ddeployment.security.SSLv2Hello=false -Ddeployment.security.SSLv3=false -Ddeployment.security.TLSv1=false

推荐答案

这是下一个要找的人的解决方法:

This is the fix for the next guy looking:

mail.smtp.starttls.enable=true;
mail.smtp.ssl.protocols=TLSv1.2;

这篇关于如何强制 JavaMailSenderImpl 使用 TLS1.2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何使用 JAVA 向 COM PORT 发送数据?
How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)...
2024-08-25 Java开发问题
21

如何使报表页面方向更改为“rtl"?
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)...
2024-08-25 Java开发问题
19

在 Eclipse 项目中使用西里尔文 .properties 文件
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)...
2024-08-25 Java开发问题
18

有没有办法在 Java 中检测 RTL 语言?
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)...
2024-08-25 Java开发问题
11

如何在 Java 中从 DB 加载资源包消息?
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)...
2024-08-25 Java开发问题
13

如何更改 Java 中的默认语言环境设置以使其保持一致?
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)...
2024-08-25 Java开发问题
13