前言:通过前面快速学习了SpringBoot之后,便很快爱上了SpringBoot,今天学习了使用SpringBoot发送邮件的相关知识,便想着记录一下。
- 一、首先,我们需要在pom.xml文件中引入发送邮件的依赖
<!-- 发送邮件依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<!-- 模板引擎thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
我们除了引入发送邮件的依赖,我们还引入了thymeleaf模板引擎依赖,后面我们会使用它来发送模板邮件。
- 二、在配置文件application.yml文件中写入发送邮件的配置信息
#字符集
spring.mail.default-encoding=UTF-8
#电子邮件地址
spring.mail.host=smtp.qq.com
#端口
spring.mail.port=587
#授权密码(不是登陆密码)
spring.mail.password=xxxxxxxxxxxxxxxx
#邮箱账号名
spring.mail.username=xxxxxxxxxx@qq.co