SpringBoot发送邮件,QQ邮箱

编程入门 行业动态 更新时间:2024-10-11 09:29:43

SpringBoot<a href=https://www.elefans.com/category/jswz/34/1770428.html style=发送邮件,QQ邮箱"/>

SpringBoot发送邮件,QQ邮箱

一.网页版QQ邮箱—>设置—>账户—>选择开启POP3/SMTP 服务【如果已经开启,就关闭再开启就可以获取授权码了】



二.编写写application.yml 导入对应的jar包

spring:mail:#smtp服务主机  qq邮箱则为smtp.qqhost: smtp.qq#服务协议protocol: smtp# 编码集default-encoding: UTF-8#发送邮件的账户username: xxxxxxxxxx0@qq#相对应的授权码password: xxxxxxxxxxxxxxtest-connection: trueproperties:mail:smtp:auth: truestarttls:enable: truerequired: true

pom.xml里面导包

      <!--email包--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mail</artifactId></dependency>

三.ServiceImpl实现类里面注入JavaMailSender

@Autowiredprivate JavaMailSender mailSender;@Overridepublic Result sendEmail() {//创建简单邮件消息SimpleMailMessage message = new SimpleMailMessage();//谁发的,发件人的邮箱,也就是你的邮箱message.setFrom("xxxxxx@qq");//谁要接收,这里面可以写数组,可以一次发送message.setTo("xxxxxx@qq");//邮件标题-自定义message.setSubject("你的注册验证码");//邮件内容-自定义message.setText("这里是内容哈哈哈哈");try {mailSender.send(message);return new Result(true, "发送普通邮件成功");} catch (MailException e) {e.printStackTrace();return new Result(true, "发送普通邮件成功");}}

五.测试

更多推荐

SpringBoot发送邮件,QQ邮箱

本文发布于:2024-03-09 18:39:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1725761.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送邮件   邮箱   SpringBoot   QQ

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!