SpringBoot项目整合JavaMail 采用smtp协议发送邮箱 邮箱采用的是QQ邮箱
在windows环境下开发没有问题、端口采用25端口正常发送
部署在Linux上面报如下错误
原因:服务器是阿里云的ECS服务器
阿里云默认禁用了25端口所以通过25端口去链接QQ邮箱服务器无法链接成功
mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.163.com, 25; timeout -1;
nested exception is:
java.net.ConnectException: 连接超时 (Connection timed out). Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.163.com, 25; timeout -1;
nested exception is:
解决方案: 修改端口25为456端口,456端口为SSL端口 所以修改端口的同时进行协议转换 。解决方案如下,修改yml文件配置
mail:
host: smtp.qq.com
username:
password:
protocol: smtp
default-encoding: UTF-8
port: 465
properties:
mail:
smtp:
ssl:
enable: true
socketFactory:
port: 465
class: javax.net.ssl.SSLSocketFactory
网友评论