admin管理员组文章数量:1559732
配置腾讯邮箱获取邮箱连接密码
腾讯邮箱–>设置–>账户–>打开POP3/SMTP服务–>获取授权码
SpringBoot配置
POM文件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
application.properties配置
#这里指明发送方的邮箱
spring.mail.username=xxxx@qq
#password填我们刚刚说的授权码
spring.mail.password=你自己获取的授权码
spring.mail.protocol=smtp
spring.mail.default-encoding=utf-8
#下面几句是必须
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.application.name=spirng-boot-mail
spring.mail.host=smtp.qq
默认的邮箱服务器端口
spring.mail.port=25
springboot测试程序
service层
@Service
public class MailService {
@Autowired
private JavaMailSender javaMailSender;
public void sendMail(String to, String subject, String content) {
SimpleMailMessage mailMessage=new SimpleMailMessage();
mailMessage.setFrom("xxxxxxxxx@qq");//发起者
mailMessage.setTo(to);//接受者
//多人mailMessage.setTo("1xx","2xx","3xx");
mailMessage.setSubject(subject);
mailMessage.setText(content);
try {
javaMailSender.send(mailMessage);
System.out.println("发送邮件成功");
}catch (Exception e){
System.out.println("发送邮件失败");
}
}
}
测试
@Test
public void sendMailTest(){
mailService.sendMail("xxx","这里是邮件的主题","助理是邮件的内容");//第一个参数是邮件的接收方
}
本文标签: 腾讯发送邮件框架邮箱SpringBoot
版权声明:本文标题:springboot框架使用腾讯邮箱自动发送邮件 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1727423603a1113843.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论