解决java发邮件错误javax.net.ssl.SSLHandshakeException: No appropriate protocol

java发送邮件时报以下错误信息:

javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher

java 复制代码
[com.bm6api.controller.v1.AppUserController] - sendLoginAuthCodeMail 发送登录验证码邮件 : {"code":200,"info":"Success"}
[org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor] - Written [{"code":200,"info":"Success"}] as "text/html" using [org.springframework.http.converter.StringHttpMessageConverter@3c3f40cb]
[org.springframework.web.servlet.DispatcherServlet] - Null ModelAndView returned to DispatcherServlet with name 'SpringMVC': assuming HandlerAdapter completed request handling
[org.springframework.web.servlet.DispatcherServlet] - Successfully completed request
[freemarker.cache] - TemplateLoader.findTemplateSource("email_login_auth_en_US.ftl"): Not found
[freemarker.cache] - TemplateLoader.findTemplateSource("email_login_auth_en.ftl"): Not found
[freemarker.cache] - TemplateLoader.findTemplateSource("email_login_auth.ftl"): Found
[freemarker.cache] - "email_login_auth.ftl"("en_US", UTF-8, parsed): using cached since 
javax.mail.MessagingException: Could not connect to SMTP host: smtp.exmail.qq.com, port: 465;
  nested exception is:
        javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
        at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1963)
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
        at javax.mail.Service.connect(Service.java:345)
        at javax.mail.Service.connect(Service.java:226)
        at javax.mail.Service.connect(Service.java:246)
        at com.bm6api.service.impl.MailServiceImpl.sendEmail(MailServiceImpl.java:92)
        at com.bm6api.thread.EmailSendThread.run(EmailSendThread.java:34)
Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
        at sun.security.ssl.HandshakeContext.<init>(HandshakeContext.java:171)
        at sun.security.ssl.ClientHandshakeContext.<init>(ClientHandshakeContext.java:106)
        at sun.security.ssl.TransportContext.kickstart(TransportContext.java:238)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:410)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:389)
        at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:528)
        at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:333)
        at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:208)
        at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1927)
        ... 6 more

解决办法1

修改JDK配置,将TLSv1和TLSv1.1从配置项里去除。配置文件路径在

java 复制代码
$JAVA_HOME/jre/lib/security/java.security

定位到配置文件的

java 复制代码
jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA

所在行,注释掉原来那行,复制到下方,去掉TLSv1和TLSv1.1,保存。

java 复制代码
# Note: This property is currently used by the JDK Reference implementation.
# It is not guaranteed to be examined and used by other implementations.
#
# Example:
#   jdk.tls.disabledAlgorithms=MD5, SSLv3, DSA, RSA keySize < 2048, \
#       rsa_pkcs1_sha1
#jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA, \
jdk.tls.disabledAlgorithms=SSLv3, RC4, DES, MD5withRSA, \
    DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \
    include jdk.disabled.namedCurves

重新运行你自己的java服务进程即可。

相关推荐
LGL6030A3 分钟前
Java学习历程14——制作一款五子棋游戏(4)
java
你好,我叫C小白30 分钟前
C语言 常量,数据类型
c语言·开发语言·数据类型·常量
小红帽2.01 小时前
从ioutil到os:Golang在线客服聊天系统文件读取的迁移实践
服务器·开发语言·golang
qq_589568101 小时前
javaweb开发笔记—— 前端工程化
java·前端
Zafir20242 小时前
Qt实现TabWidget通过addTab函数添加的页,页内控件自适应窗口大小
开发语言·c++·qt·ui
阿巴~阿巴~2 小时前
深入解析C++非类型模板参数
开发语言·c++
码农小灰2 小时前
Kafka消息持久化机制全解析:存储原理与实战场景
java·分布式·kafka
程序员鱼皮3 小时前
太香了!我连夜给项目加上了这套 Java 监控系统
java·前端·程序员
L2ncE4 小时前
高并发场景数据与一致性的简单思考
java·后端·架构
武昌库里写JAVA4 小时前
使用 Java 开发 Android 应用:Kotlin 与 Java 的混合编程
java·vue.js·spring boot·sql·学习