springboot 测试发送邮件
首先在pom文件引入依赖:
<!--email依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
配置 文件:
spring.mail.host=smtp.163.com //本人 用的是163邮箱
spring.mail.username=****@163.com //邮箱地址
spring.mail.password=授权码
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
注意:邮箱要开启pop3,smtp服务,获取授权码

写个简单的测试类:
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringbootmailApplicationTests {
@Autowired
private JavaMailSender mailSender;
@Test
public void sendSimpleMail() throws Exception {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("****@163.com"); //发送方
message.setTo("***@qq.com"); //目标
message.setSubject("主题:简单邮件");
message.setText("测试邮件内容");
mailSender.send(message);
}
}
以上是发送邮件的小测试。
springboot 测试发送邮件的更多相关文章
- 关于使用commons-email包测试发送邮件遇到的问题
项目中有个需求是这样的:客户办理某一项业务,当用户成功提交业务办理信息后,系统生成一个业务随机码给用户,以此作为以后的业务办理结果查询依据.鉴于随机码较长,方便用户记录,在生成随机码的同时,提供用户发 ...
- springboot测试、打包、部署
本文使用<springboot集成mybatis(一)>项目,依次介绍springboot测试.打包.部署. 大多数朋友是做后端的,也就是为其他系统或者前端UI提供Rest API服务. ...
- SpringBootTest单元测试实战、SpringBoot测试进阶高级篇之MockMvc讲解
1.@SpringBootTest单元测试实战 简介:讲解SpringBoot的单元测试 1.引入相关依赖 <!--springboot程序测试依赖,如果是自动创建项目默认添加--> &l ...
- Redis3.2.5 集群搭建以及Spring-boot测试
1:集群中的机器信息 IP PORT 192.168.3.10 7000,7001,7002 192.168.3.11 7004,7005,7006 2:安装Redis 分别在10与11机器上面安装R ...
- java springboot+maven发送邮件
springboot+maven发送邮件 废话不多说直接上代码 1. pom 文件导入jar包 <!--邮件发送--> <dependency> <groupId> ...
- springboot测试启动报错java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
springboot测试启动报错: java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you ne ...
- SpringBoot测试类启动错误 java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
报错 java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @Cont ...
- 使用 SpringBoot 配置发送邮件功能
1.使用 SpringBoot 配置发送邮件功能 项目总体结构 用户表设计 SET FOREIGN_KEY_CHECKS=0; CREATE DATABASE sample; USE sample; ...
- springboot + rabbitmq发送邮件(保证消息100%投递成功并被消费)
前言: RabbitMQ相关知识请参考: https://www.jianshu.com/p/cc3d2017e7b3 Linux安装RabbitMQ请参考: https://www.jianshu. ...
随机推荐
- PageObject 页面对象模式
一.PageObject 页面对象设计模式 (一个页面建一个类,即对象,页面对象) 每个页面都建对应的class,类中包含了页面的输入框.标题.元素等元素,测试代码中测试这个页面时,只需要调用这个页 ...
- gson 带泛型的转换
json转对象 public static <T> T json2Obj(String json, Class<T> cls) { Gson gson = new Gson() ...
- JS基础_标识符
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- springboot页面模板thymeleaf的简单用法
thymeleaf基础语法: 变量输出与字符串操作: th:text 表示在页面输出值 th:value 表示将一个值放入input标签的value中 判断字符串是否为空: thymele ...
- JS根据一个经纬度及距离角度,算出另外一个经纬度
var mapNumberUtil = {}; /** * 根据一个经纬度及距离角度,算出另外一个经纬度 * @param {*} lng 经度 113.3960698 * @param {*} la ...
- Spring 资源加载
pom.xml ``` org.springframework spring-core 4.3.14.RELEASE org.springframework spring-beans 4.3.16.R ...
- linux创建定时任务发送钉钉通知
一.现在钉钉里面添加机器人 添加成功后,复制出Webhook链接. 注意,自定义关键字时你的发送信息中一定要完整包含关键字 二.找到自己的服务器 1. sudo su 切换到root用户 2.cron ...
- 数据库 (二):MySQL密码策略与用户管理
为了加强安全性,MySQL5.7为root用户随机生成了一个密码可通过# grep "password" /var/log/mysqld.log 命令获取MySQL的临时密码用该密 ...
- vim 搜索 向前,向后
vim 搜索可以是 / 或者 ?,前者是往下找,后者是往前找. 用 n 查找下一个的时候,就和这两个指令指定的方向相同.如果你想改变方向的话,比如想往下找,那么 / 完了直接回车就行了.表示再次使用上 ...
- 010-SaltStack及SaltStack Web UI安装部署
saltstack web uiweb平台界面 saltapi项目主页:http://salt-api.readthedocs.org/en/latest/ halite 项目主页:https://g ...