美文网首页
Java发送Email邮件问题

Java发送Email邮件问题

作者: TZX_0710 | 来源:发表于2020-02-26 22:00 被阅读0次

SpringBoot项目整合JavaMail 采用smtp协议发送邮箱 邮箱采用的是QQ邮箱
在windows环境下开发没有问题、端口采用25端口正常发送
部署在Linux上面报如下错误
原因:服务器是阿里云的ECS服务器
阿里云默认禁用了25端口所以通过25端口去链接QQ邮箱服务器无法链接成功

mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.163.com, 25; timeout -1;
  nested exception is:
        java.net.ConnectException: 连接超时 (Connection timed out). Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.163.com, 25; timeout -1;
  nested exception is:

解决方案: 修改端口25为456端口,456端口为SSL端口 所以修改端口的同时进行协议转换 。解决方案如下,修改yml文件配置

  mail:
    host: smtp.qq.com
    username: 
    password:
    protocol: smtp
    default-encoding: UTF-8
    port: 465
    properties:
      mail:
        smtp:
          ssl:
            enable: true
          socketFactory:
            port: 465
            class: javax.net.ssl.SSLSocketFactory

相关文章

网友评论

      本文标题:Java发送Email邮件问题

      本文链接:https://www.haomeiwen.com/subject/sdjgchtx.html