0%
导入mail包
1 2 3 4
| <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency>
|
application.yml配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| spring: mail: protocol: smtp host: smtp.qq.com port: 587 username: password: properties: mail: smtp: auth: true starttls: enable: true required: true
|
端口配置信息,仅供参考

Tests
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class) @SpringBootTest public class BlogApplicationTests { @Resource private JavaMailSender javaMailSender;
@Value("${spring.mail.username}") private String sender;
@Test public void contextLoads() { SimpleMailMessage message = new SimpleMailMessage(); message.setFrom(sender); message.setTo("xxx@qq.com"); message.setSubject("测试邮件(邮件主题)"); message.setText("这是邮件内容"); javaMailSender.send(message); }
}
|
关于QQ授权码

