1、引入依赖
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>2.7.1</version>
</dependency>
2、application.yml添加配置
注意:password不是qq密码,而是邮箱授权码
spring:
mail:
host: smtp.qq.com
username: 165xxxxxxx@qq.com
password: zjdxxxxxxxxxxxx
default-encoding: utf-8
properties:
mail:
smtp:
auth: true
starttls:
enable: true
required: true
在qq邮箱设置里面点开启,发送短信,就能获取到授权码