依赖;
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
配置:
mail:
host: xxx
username: xxx@xxx.com
password: xxx
properties:
mail:
smtp:
auth: true
socketFactory:
class: javax.net.ssl.SSLSocketFactory
port: 465
也可以用基于25端口的配置:
spring.mail.host=xxx
spring.mail.username=xxx
spring.mail.password=xxx
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
源码: github
注意:
云服务器要是阿里云的还是用456端口的配置吧,不要去申请解锁25端口了