javaMail的使用
-
先来展示下收到邮件的效果图:
-
准备工作
- 邮箱服务器地址:这里使用新浪邮箱,登录你的新浪邮箱,开启SMTP
- 目标邮箱地址:可以是自己的qq邮箱,能接到邮件就行
-
maven引入依赖包,thymeleaf有提供htmlmail模板
<!--mail--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency> <!--thymeleaf--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
-
配置相关信息
spring: thymeleaf: cache: false mode: LEGACYHTML5 mail: # 邮箱设置里可以找到 host: smtp.sina.com # 去页面开启SMTP username: password: default-encoding: UTF-8
-
编写相关代码