使用这个的时候 请注意每秒发送的邮件数量,如果一秒好几封的话很有可能带宽被占满
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
#spring.mail.host=smtp.qq.com
spring.mail.host=smtp.qq.com
# 设置用户名
spring.mail.username=834109@qq.com
# 设置密码
spring.mail.password=
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
@Autowired
private JavaMailSender mailSender;
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("[email protected]");//发送者.
message.setTo(toMailAdress);//接收者.
message.setSubject(title);//邮件主题.
message.setText(content);//邮件内容.
mailSender.send(message);//发送邮件