JAVA使用腾讯企业邮箱发送邮件时报错Could not connect to SMTP host
最近做一个邮件发送功能的时候,发现腾讯企业邮的邮箱,用java发送邮件的时候一直报错:Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.exmail.qq.com, port: 465, response: -1. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.exmail.qq.com, port: 465, response: -1
发邮件使用的spring-boot-starter-mail
,配置文件如下:
1 | # 设置邮箱主机 |
查阅各种资料后发现,配置文件应当加入下面的配置:
1 | spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory |
将这三行加入到配置文件里就可以正常发送邮件了
JAVA使用腾讯企业邮箱发送邮件时报错Could not connect to SMTP host
https://www.stonewu.com/post/use-tencent-exmail-send-error.html