admin管理员组文章数量:1559388
SpringBoot+JavaMailSender+ 腾讯企业邮箱配置
1. 引入spring-boot-starter-mail 依赖包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
2. 在application.yml配置邮箱基本信息
spring:
mail:
host: smtp.exmail.qq
port: 465
username: xxx@xx
password: xxxx
protocol: smtp
properties:
mail:
smtp:
auth: true
ssl:
enable: true
socketFactory:
class: com.sun.mail.util.MailSSLSocketFactory
fallback: false
3. 实现代码
@Autowired
JavaMailSender javaMailSender;
public void testSend() {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("XXX@xxx"); //发送者邮箱地址 此地址一定要和yml邮箱一致
message.setTo("xxx@xxx"); //收件人邮箱地址
message.setSubject("测试主题");
message.setText("测试内容");
jms.send(message);
}
注意:
如果代码报:501 mail from address must be same as authorization user 错误 ;引起原因是yml中配置的邮箱地址和代码中message.setFrom(xx@xx);不一致导致;
本文标签: 腾讯企业邮箱SpringBootJavaMailSender
版权声明:本文标题:SpringBoot+JavaMailSender+ 腾讯企业邮箱配置 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1727422222a1113708.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论