admin管理员组

文章数量:1559070

springboot javamailsender 腾讯企业邮箱配置

1. 引入spring-boot-starter-mail 依赖包

        
            org.springframework.boot
            spring-boot-starter-mail
        

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);不一致导致;

 

本文标签: 腾讯企业邮箱springboot