程序员

SpringBoot+JavaMailSender+ 腾讯企业邮箱配置

作者:admin 2021-06-29 我要评论

SpringBootJavaMailSender 腾讯企业邮箱配置 1. 引入spring-boot-starter-mail 依赖包 dependency groupIdorg.springframework.boot/groupId artifactIdspring-b...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

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.com
    port: 465
    username: xxx@xx.com
    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.com"); //发送者邮箱地址  此地址一定要和yml邮箱一致

		message.setTo("xxx@xxx.com"); //收件人邮箱地址

		message.setSubject("测试主题");

		message.setText("测试内容");

		jms.send(message);

	}

?注意:

如果代码报:501 mail from address must be same as authorization user 错误? ;引起原因是yml中配置的邮箱地址和代码中message.setFrom(xx@xx.com);不一致导致;

?
;原文链接:https://blog.csdn.net/qq_34287953/article/details/115671687

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • SpringBoot+JavaMailSender+ 腾讯企业

    SpringBoot+JavaMailSender+ 腾讯企业

  • Kubernetes二进制部署

    Kubernetes二进制部署

  • [译] APT分析报告:09.伊朗APT34更新武

    [译] APT分析报告:09.伊朗APT34更新武

  • 园区网络的IP地址资源规划 使用VLSM(

    园区网络的IP地址资源规划 使用VLSM(

腾讯云代理商
海外云服务器