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