1.开启发送端邮箱的smtp服务,登录进入后设置
2.引入依赖包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
3.添加设置信息
#配置邮件消息
spring.mail.host=smtp.qq.com
#发送邮件者信箱
spring.mail.username=******@qq.com
#这里不是邮箱的登录密码,而是开启PO3/SMTP服务时邮箱的授权码
spring.mail.password= ******
spring.mail.default-encoding=UTF-8
spring.mail.port=587
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.debug=true
4.添加邮件工具类
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
import java