构架工程
创建一个springboot工程,在其pom文件加入: Spring Cloud大型企业分布式微服务云架构源码请加一七九一七四三三八零
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
添加配置
spring.mail.host=smtp.163.com
spring.mail.username=miles02@163.com
spring.mail.password=
spring.mail.port=25
spring.mail.protocol=smtp
spring.mail.default-encoding=UTF-8
在password 中填写自己的邮箱密码。
测试发邮件
测试代码清单如下:
package com.forezp;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.sprin