You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot中Jakarta Mail无法验证服务器身份问题求助

Spring Boot发送邮件TLS连接验证失败问题

我在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: 

我已经尝试了多种解决方案,当前配置如下:

spring.mail.host=example.com
spring.mail.port=587
spring.mail.username=noreply@example.com
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)

内容的提问来源于stack exchange,提问作者Simon Martinelli

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 02:58:14