首先要去邮箱打开POP3/SMTP权限:

然后会提供个授权码,用来发送邮件。忘记了,可以点生成授权码再次生成。

1、引入spring boot自带的mail依赖,这里版本用的:<spring-boot.version>1.4.3.RELEASE</spring-boot.version>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>${spring-boot.version}</version>
<scope>provided</scope>
</dependency>

2、spring boot配置文件添加邮箱参数信息

spring.mail.host=smtp.qq.com
spring.mail.username=你的qq号码@qq.com
spring.mail.password=qq邮箱开启SMTP提供的授权码(注意:不是你的qq邮箱密码)
#下面一般不用动
spring.mail.default-encoding=${spring.http.encoding.charset}
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=3000
spring.mail.properties.mail.smtp.writetimeout=5000
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true

3、测试发送

@Autowired
private JavaMailSender mailSender; @Value("${spring.mail.username}")
private String from; SimpleMailMessage smm = new SimpleMailMessage();
smm.setFrom(from);
smm.setTo("发送方邮件地址");
smm.setSubject("springboot测试邮件");
smm.setText("简单文本邮件测试发送!");
mailSender.send(smm);

最新文章

  1. 当我谈 &quot;加班有罪&quot; 我在谈什么?
  2. Ubuntu杂记——Ubuntu自带拼音输入发杂乱不堪
  3. c++ DLL-&gt;DEF-&gt;LIB
  4. VIM使用(二) 浏览内核源代码
  5. 安装 vue.js和第一个hello world
  6. webstorm配置scss自动编译路径
  7. Tomcat 使用说明
  8. channelartlist添加栏目链接
  9. maven search
  10. ASP.NET MVC5 学习笔记-4 OWIN和Katana
  11. Beautifulsoup 和selenium 的查询
  12. JAVA基础第六组(5道题)
  13. 《前端之路》之三 数组的属性 &amp;&amp; 操作方法(上)
  14. 52 和 52Rc 通过IIC写入数据
  15. wx小程序-音频视频!
  16. C++ 跨语言调用 Java
  17. 【待完成】[MapReduce_9] MapReduce 的 Shuffle 机制
  18. SSH框架搭建demo
  19. 使用Gitblit 在Windows2008 r2上部署Git Server(完整版)
  20. lua内存管理

热门文章

  1. CSS——背景及应用
  2. 字符串匹配dp+bitset,滚动数组优化——hdu5745(经典)
  3. NX二次开发-获取面的法向向量UF_MODL_ask_face_data
  4. 拾遗:Perl 基础语法
  5. postgresql+java数据类型对照
  6. 17-MySQL-Ubuntu-数据表的查询-分页(六)
  7. java获得磁盘、网络实时I/O速率
  8. iOS开发系列-Runtime运用场景
  9. RabbitMQ学习第一记:用java连接RabbitMQ
  10. Appium 微信 webview 的自动化技术