springboot项目在阿里云服务器上发送邮件失败
springboot项目部署在ecs服务器上后,调用发送邮件的接口时发送错误:
Exception in thread "Thread-8" org.springframework.mail.MailSendException: Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.mxhichina.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.mxhichina.com, 25; timeout -1;
nested exception is:
java.net.ConnectException: Connection timed out (Connection timed out); message exception details (1) are:
Failed message 1:
com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.mxhichina.com, 25; timeout -1;
nested exception is:
java.net.ConnectException: Connection timed out (Connection timed out)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2118)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:712)
at javax.mail.Service.connect(Service.java:366)
at org.springframework.mail.javamail.JavaMailSenderImpl.connectTransport(JavaMailSenderImpl.java:501)
at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:421)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:345)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340)
at it.ozimov.springboot.mail.service.defaultimpl.DefaultEmailService.send(DefaultEmailService.java:138)
该接口在本地测试是可以成功发送邮件的,但部署到ecs就不行了。看上面的错误信息是连接不上smtp.mxhichina.com
的25
端口,我在服务器上使用命令telnet smtp.mxhichina.com 25
测试确实也连不上。不知道是不是和阿里云服务器默认封禁25端口有关。
请教一下这个问题怎么解决?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以改用ssl加密465端口发送邮件,spring javamail配置如下:
参考:解决阿里云ECS禁用25端口导致发邮件失败