springboot2.0集成mail发qq邮件

1.maven依赖

<!-- https://mvnrepository.com/artifact/com.sun.mail/javax.mail -->
<dependency>
    <groupId>com.sun.mail</groupId>
    <artifactId>javax.mail</artifactId>
    <version>1.6.1</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
</dependency>

2.配置信息

spring.mail.host=smtp.qq.com
spring.mail.port=587
//发件人
[email protected]
//这个是邮箱里面自己设置的授权码
spring.mail.password=dbgqaklwpfambbif
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.debug=true

注意:红色的是需要修改的

3.使用

@Autowired
private JavaMailSender mailSender;
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("[email protected]");
message.setTo("[email protected]");
message.setSubject("邮件轰炸");
message.setText("邮件轰炸,哈哈");
mailSender.send(message);

完成,就是这样简单,哈哈,没会员每天只能发100条

猜你喜欢

转载自blog.csdn.net/qq_37162911/article/details/81981753