gpt4 book ai didi

javax.mail - 强制 IMAP 使用 TLS1.2+ - "Received fatal alert: protocol_version"

转载 作者:行者123 更新时间:2023-12-02 09:04:00 26 4
gpt4 key购买 nike

我的应用程序在通过 IMAP 阅读邮件时遇到问题。

应用程序读取多个 imap 帐户。应用可以连接到除需要使用 TLS1.2 或 TLS1.3 的服务器之外的所有服务器。

我有这个代码:

System.out.println("SSLContext getProtocols(): " + String.join(" ", SSLContext.getDefault().getSupportedSSLParameters().getProtocols()));

Properties props = new Properties();
props.put("mail.imap.auth", "true");
props.put("mail.imap.ssl.enable", "true");
props.put("mail.imap.starttls.enable", "false");
props.put("jdk.tls.client.protocols", "TLSv1.2 TLSv1.3");
props.put("mail.imap.ssl.protocols", "TLSv1.2 TLSv1.3");

Session session = Session.getDefaultInstance(props);
Store store = session.getStore("imaps");
store.connect(mailConf.getImapServer(), mailConf.getImapServerPort(), mailConf.getImapUser(), mailConf.getImapPass());
Folder inbox = store.getFolder(mailConf.getImapMailFolder());
inbox.open(Folder.READ_ONLY);

并使用以下方式运行应用程序:

java -Djdk.tls.client.protocols="TLSv1.2,TLSv1.3" \
-Ddeployment.security.SSLv2Hello=false \
-Ddeployment.security.SSLv3=false \
-Ddeployment.security.TLSv1=false \
-Ddeployment.security.TLSv1.1=false \
-Ddeployment.security.TLSv1.2=true \
-Ddeployment.security.TLSv1.3=true \
-jar myApp.jar

对于需要 TLS1.2+ 的 IMAP 服务器,我看到以下输出:

SSLContext getProtocols(): TLSv1.3 TLSv1.2 TLSv1.1 TLSv1 SSLv3 SSLv2Hello
Jan 29 11:41:19 myhost myapp[22101]: 2020-01-29 11:41:19 ERROR e.v.MyAppApplication$$EnhancerBySpringCGLIB$$8bb5321c:68 - Imap readMail() error: Received fatal alert: protocol_version

我正在使用 Java 11:

# java --version
openjdk 11.0.4 2019-07-16
OpenJDK Runtime Environment (build 11.0.4+11-post-Debian-1deb10u1)
OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Debian-1deb10u1, mixed mode, sharing)

我做错了什么?如何强制 imap 连接使用 TLS1.2+?

谢谢。

最佳答案

对于 SMTP:mail.smtps.ssl.protocols=TLSv1.2

对于 IMAP:mail.imaps.ssl.protocols=TLSv1.2

对于 POP3:mail.pop3s.ssl.protocols=TLSv1.2

关于javax.mail - 强制 IMAP 使用 TLS1.2+ - "Received fatal alert: protocol_version",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59965481/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com