今天在服务器上正常运行项目的时候,邮件都没有发出去。查看日志,发现java调用邮件的SSL的时候,抛出一个异常。
2021-11-19 12:00:00.116 [pool-2-thread-1] ERROR o.s.s.support.TaskUtils$LoggingErrorHandler - Unexpected error occurred in scheduled task.
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.qiye.aliyun.com, port: 465;
nested exception is:
javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate). Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.qiye.aliyun.com, port: 465;
nested exception is:
javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:432)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:345)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340)
最后才发现是因为jdk1.8版本导致SSL调用权限上有问题。
解决办法:找到jdk 1.8安装目录,找到java.security。找到对应的SSLv3,删除掉,重启项目就好了。(删掉SSLv3就是允许SSL调用)。
注:不知道是不是不同邮箱提供商是用的是不同的协议,我连接阿里云企业邮箱 smtp.qiye.163.com:465发现去掉SSLv3没有效果,必须去掉TLSv1,TLSv1.1
另附:开启ssl的bug日志:-Djavax.net.debug=ssl,当然也可以-Djavax.net.debug=all,开启后如果没有修改jdk配置,你会看到如下输出:
Ignoring disabled protocol: SSLv3