使用SpringBoot + JavaMailSender 发送邮件报错 Mail server connection failed;Could not connect to SMTP host

使用SpringBoot + JavaMailSender 发送邮件报错 Mail server connection failed;Could not connect to SMTP host

报错信息如下:

java

org.springframework.mail.MailSendException: Mail server connection failed; nested exception is Javax.mail.MessagingException: Could not connect to SMTP host: smtp.qq.***, port: 465, response: -1. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.qq.***, port: 465, response: -1

解决办法:

在 application.yml 中将邮件配置为 SSL 连接

yml

spring:
  mail:
    host: smtp.qq.***
    username: 你的邮箱账号
    password: 你的邮箱授权码(QQ邮箱)
    port: 465
    protocol: smtp
    default-encoding: utf-8
    properties:
      mail:
        smtp:
          auth: true
          starttls:
            enable: true
            required: true
          ssl:
            enable: true
          socketFactory:
            port: 465
            class: javax.***.ssl.SSLSocketFactory

如果你使用的是 properties 文件,应该修改为:

properties

# JavaMailSender 配置
spring.mail.host=smtp.qq.***
spring.mail.username=你的邮箱账号
spring.mail.password=你的邮箱授权码(QQ邮箱)
spring.mail.port=465
spring.mail.default-encoding=utf-8
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
# SSL 配置
spring.mail.protocol=smtp
spring.mail.properties.mail.smtp.ssl.enable=true
spring.mail.properties.mail.smtp.socketFactory.port=465
spring.mail.properties.mail.smtp.socketFactory.class=javax.***.ssl.SSLSocketFactory

推荐一个 yml、properties 文件在线转换的网站 在线yaml转properties-在线properties转yaml-ToYaml.***

 

来源:https://www.***blogs.***/songjilong/p/12577010.html

转载请说明出处内容投诉
CSS教程_站长资源网 » 使用SpringBoot + JavaMailSender 发送邮件报错 Mail server connection failed;Could not connect to SMTP host

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买