記錄一次阿里雲伺服器 465埠傳送163郵件 springboot yml配置
阿新 • • 發佈:2020-11-03
檢視連結:https://www.cnblogs.com/east7/p/13406120.html
在Spring Boot專案中,使用org.springframework.mail.javamail.JavaMailSender傳送郵件拋異常,異常資訊:
Mail server connection failed; nested exception is javax.mail.MessagingException: Got bad greeting from SMTP host: smtp.163.com, port: 465,
response: [EOF]. Failed messages: javax.mail.MessagingException: Got bad greeting from SMTP host: smtp.163.com, port: 465, response: [EOF]
問題分析:設定郵件協議的時候,配置如下:
spring.mail.protocol=smtp
#設定ssl埠
spring.mail.port=465
注意,是smtp,結尾沒有字母s。另外,在不設定該屬性的時候,系統預設使用SMTP協議。
解決方案:修改配置檔案,使用郵件傳輸協議SMTPS,使得傳輸協議與埠465相匹配:
spring.mail.protocol=smtps
結論:重啟服務,經驗證問題搞定。其實,網上很多人寫的部落格都把配置資訊寫錯了,我就是抄錯了,這裡記下來,亡羊補牢。