SpingBoot___5种简单的发生邮件的小demo
过程图
这里使用的是qq邮箱,先去你的qq邮箱开启SMIP和POP3
然后它会叫你发短信拿授权码,那个授权码需要记住,后面有用。
依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
application.properties
#配置 SMTP 服务器地址
spring.mail.host=smtp.qq.com
#SMTP 服务器的端口
spring.mail.port=587
#配置邮箱用户名
spring.mail.username=发送者@qq.com
#申请到的授权码
spring.mail.password=授权码
#默认的邮件编码
spring.mail.default-encoding=UTF-8
#配饰 SSL 加密工厂
spring.mail.properties.mail.smtp.socketFactoryClass=javax.net.ssl.SSLSocketFactory
#表示开启 DEBUG 模式
spring.mail.properties.mail.debug=true
Pojo
/**
*