目录

  • ​​一、问题:​​
  • ​​二、原因:​​
  • ​​三、解决办法:​​
  • ​​3.1 申请解封25端口:​​
  • ​​3.2 修改端口,改为SSL连接:​​

一、问题:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.boot.autoconfigure.mail.MailSenderValidatorAutoConfiguration’: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.mail.MailSenderValidatorAutoConfiguration]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Mail server is not available

二、原因:

出于安全考虑,某某云默认封禁 TCP 25 端口出方向的访问流量,无法在某某云上的云服务器通过 TCP 25 端口连接外部地址。

三、解决办法:

3.1 申请解封25端口:

​https://help.aliyun.com/knowledge_detail/56130.html​

3.2 修改端口,改为SSL连接:

yml版:

spring:
mail:
host: smtp.qq.com
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.net.ssl.SSLSocketFactory

properties版:

# JavaMailSender 配置
spring.mail.host=smtp.qq.com
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.net.ssl.SSLSocketFactory