解决springboot项目部署到阿里云服务器邮箱无法发送邮件而本地可以问题(亲测有用)

解决springboot项目部署到服务器邮箱无法发送邮件而本地可以问题(亲测有用)

前言: 由于SpringBoot项目有发送邮箱功能,但是部署到服务器上却出现无法发送问题!但是本地却可以!!大致看了一下应该是端口的问题!

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.mail.MailSendException: Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.qq.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.qq.com, 25; timeout -1;
  nested exception is:
 java.net.ConnectException: Connection timed out (Connection timed out); message exceptions (1) are:
Failed message 1: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.qq.com, 25; timeout -1;
  nested exception is:
 java.net.ConnectException: Connection timed out (Connection timed out)] with root cause

前篇踩雷: 试了网友的这个方法!试了没有用!(也可能自己项目用不了吧!!也不能说别人的没啥用哈哈哈哈)
解决springboot项目部署到阿里云服务器邮箱无法发送邮件而本地可以问题(亲测有用)_第1张图片
后来: 翻了别的csdn,试了可以用!

  • 在application.properties添加以下代码
# SSL Config
spring.mail.port=465
spring.mail.protocol=smtp
spring.mail.default-encoding=UTF-8
spring.mail.properties.mail.smtp.ssl.enable=true
spring.mail.properties.mail.smtp.socketFactory.port=465
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory

即为:
解决springboot项目部署到阿里云服务器邮箱无法发送邮件而本地可以问题(亲测有用)_第2张图片

参考文章:阿里云发送不了邮件,SpringBoot 使用SSL邮箱发送邮件

成功啦!!!!!!!

你可能感兴趣的:(spring,boot,服务器,阿里云)