mail:
host: smtp.aliyun.com
username:
password:
port: 25
protocol: smtp
default-encoding: UTF-8
以上本地Windows環境測試發送郵件正常,大約在3s能收到郵件
Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.aliyun.com, 25; timeout -1;
nested exception is:
java.net.ConnectException: Connection timed out (Connection timed out). Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.aliyun.com, 25; timeout -1;
以上是部署到Linux服務器上,異常信息
原因:https://help.aliyun.com/knowledge_detail/56130.html
修改配置文件
mail:
host: smtp.aliyun.com
username:
password:
port: 465
protocol: smtp
default-encoding: UTF-8
Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.aliyun.com, port: 465, response: -1. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.aliyun.com, port: 465, response: -1
以上是再次測試接口,異常信息
mail:
host: smtp.aliyun.com
username:
password:
port: 465
protocol: smtp
default-encoding: UTF-8
properties.mail.smtp.ssl.enable: true #加上解決這問題