转载自: Got bad greeting from SMTP host: smtp.163.com, port: 465, response: [EOF]

在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

结论:重启服务,经验证问题搞定。其实,网上很多人写的博客都把配置信息写错了,我就是抄错了,这里记下来,亡羊补牢。