提问人:Simon Martinelli 提问时间:8/29/2023 最后编辑:Simon Martinelli 更新时间:9/15/2023 访问量:495
雅加达邮件:无法验证服务器身份
Jakarta Mail: Can't verify identity of server
问:
我正在尝试在Spring Boot应用程序中发送电子邮件并出现此异常
org.springframework.mail.MailSendException: Mail server connection failed. Failed messages: jakarta.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
java.io.IOException: Can't verify identity of server: example.com; message exceptions (1) are:
Failed message 1: jakarta.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
java.io.IOException: Can't verify identity of server:
我已经尝试了 SO 的几个答案,我的配置如下所示:
spring.mail.host=example.com
spring.mail.port=587
[email protected]
spring.mail.password=7Wdz@o75
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.ssl.trust=example.com
spring.mail.properties.mail.smtp.ssl.protocols=TLSv1.2
任何帮助都是值得赞赏的。
当我运行它时,我看到:-Djavax.net.debug=ssl
javax.net.ssl|DEBUG|91|http-nio-8081-exec-4|2023-08-30 11:47:15.614 CEST|null:-1|jdk.tls.keyLimits: entry = AES/GCM/NoPadding KeyUpdate 2^37. AES/GCM/NOPADDING:KEYUPDATE = 137438953472
javax.net.ssl|DEBUG|91|http-nio-8081-exec-4|2023-08-30 11:47:15.778 CEST|null:-1|duplex close of SSLSocket
javax.net.ssl|DEBUG|91|http-nio-8081-exec-4|2023-08-30 11:47:15.779 CEST|null:-1|close the underlying socket
javax.net.ssl|DEBUG|91|http-nio-8081-exec-4|2023-08-30 11:47:15.779 CEST|null:-1|close the SSL connection (initiative)
javax.net.ssl|DEBUG|91|http-nio-8081-exec-4|2023-08-30 11:47:15.780 CEST|null:-1|close inbound of SSLSocket
javax.net.ssl|WARNING|91|http-nio-8081-exec-4|2023-08-30 11:47:15.783 CEST|null:-1|SSLSocket duplex close failed. Debug info only. Exception details: (
"throwable" : {
java.net.SocketException: Socket is closed
at java.base/java.net.Socket.shutdownInput(Unknown Source)
at java.base/sun.security.ssl.BaseSSLSocketImpl.shutdownInput(Unknown Source)
at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(Unknown Source)
at java.base/sun.security.ssl.SSLSocketImpl.bruteForceCloseInput(Unknown Source)
at java.base/sun.security.ssl.SSLSocketImpl.duplexCloseOutput(Unknown Source)
at java.base/sun.security.ssl.SSLSocketImpl.close(Unknown Source)
at com.sun.mail.util.SocketFetcher.checkServerIdentity(SocketFetcher.java:698)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:636)
at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:555)
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:2184)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:766)
at jakarta.mail.Service.connect(Service.java:342)
at org.springframework.mail.javamail.JavaMailSenderImpl.connectTransport(JavaMailSenderImpl.java:518)
答:
1赞
Adrian Lange
9/15/2023
#1
似乎 Spring Boot 3.1 的默认值已从 更改为 。将其设置回去为我解决了这个问题。但这不应该是长期的解决方案。mail.smtp.ssl.checkserveridentity
false
true
因此,在您的情况下,这应该可以解决问题:
spring.mail.properties.mail.smtp.ssl.checkserveridentity=false
评论
-Djavax.net.debug=ssl