前提条件
我用的是163邮箱,优先需要授权码,如何开启授权码请参考链接
1.先上pom依赖
<!-- 邮箱依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
2.在yml设置
spring:
mail:
host: smtp.163.com
default-encoding: utf-8
password: 授权码
username: 自己的163邮箱
properties:
mail:
smtp:
ssl: enable=true