场景
使用springboot mail发邮件,利用到公司的邮件服务器。先在本地写好代码在本地单元测试时报错
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset. Failed messages: javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset
; message exception details (1) are:
Failed message 1:
javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset
大意是连接被重置
查询资料一开始说需要配置超时时间在yaml里,配置完成后仍然失败
spring:
mail:
host: XX.com
port: 25
username: XXP@XX-auto.com
properties:
mail:
debug: true
smtp:
#设置邮件发送超时时间
timeout: 25000
解决
又查询了资料,发现 connect reset 问题有人是这样说。
网络策略阻止了对SMTP服务器的请求。我与网络管理员联系,他给了我所需的权限。现在一切正常。
对啊,我现在用的是公司的邮件服务器发邮件,肯定做了限制公司,我在本地机器上怎么可能发送成功呢,哪怕我连上了公司的vpn?
然后我将程序打个jar包放到公司集群某台机器中,果然发送成功,outlook收到了邮件
后续和同事确认了之前的连接问题就是公司服务器配置问题