springboot发送邮件

1.spring-boot-start-mail

由springboot提供,添加一下依赖

org.springframework.bootspring-boot-starter-mail

2.设置qq邮箱

开通后,由产生一个 授权码。保存好,下面配置文件使用

3. 配置application.properties配置文件

#邮箱配置#平台地址,这里用的是qq邮箱,使用其他邮箱请更换spring.mail.host = smtp.qq.com#改成自己的邮箱spring.mail.username = xxxxx@qq.com#发送短信后它给你的授权码 填写到这里spring.mail.password = xxxxxx#这东西不用改spring.mail.properties.mail.smtp.ssl.enable=true##编码格式spring.mail.default-encoding=UTF-8

4.测试

@SpringBootTestpublic class MailTest {@AutowiredJavaMailSender javaMailSender;@Value("${spring.mail.username}")private String from;//谁发送的@Testpublic void test(){SimpleMailMessage message = new SimpleMailMessage();message.setSubject("邮件主体");message.setText("邮件内容");//message.setFrom(from);message.setTo("348828809@qq.com");//收件人javaMailSender.send(message);//发送}}
发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章