1. 在 pom 文件中添加依赖;
<dependency>
<groupId>org.springframework.boot</grou
pId>
<artifactId>spring-boot-starter-
mail</artifactId>
</dependency>
2. 在 common 包中新建 SendMailDemo 类,类中新增
sendMail()方法,QQ 邮箱的授权码在设置中可以找
到,SMTP 服务相关;
import lombok.extern.slf4j.Slf4j;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
@Slf4j
public class SendMailDemo {
public static void sendMail(String code)
throws MessagingException {
评论0