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. ...
随机推荐
- java执行bat代码
java执行bat代码.txt public static void runbat(String path,String filename) { String cmd = "cmd /c s ...
- 安装gitlab ce
切换到root用户,安装相关依赖 yum install curl policycoreutils openssh-server openssh-clients service sshd restar ...
- Arkady and a Nobody-men CodeForces - 860E (虚树)
大意: 给定有根树, 根节点深度为$1$. 定义$r(a,b)$为$b$子树内深度不超过$a$的节点数$-1$ 定义$z_a$为$a$的所有祖先的$r$之和. 对于所有点求出$z$的值. 一个点$y$ ...
- Eclipse使用github并开启命令行
1. 安装EGit插件 2. 导入git项目 选择Import: 选择“Clone URI” 输入想要导入的git项目地址和用户名密码: 选择代码分支: 一路点击next完成导入github项目即可. ...
- springboot JPA mysql
官方文档 https://docs.spring.io/spring-data/jpa/docs/1.11.10.RELEASE/reference/html/ 常用关键字 通常,JPA的查询创建机制 ...
- ubuntu 安装vim报错
问题:ubuntu18.04默认没有安装vim,使用 sudo apt install 提示 错误信息: 下列信息可能会对解决问题有所帮助: 下列软件包有未满足的依赖关系: vim : 依赖: vim ...
- angular项目中ts的配置编译tsconfig.json
{ "compilerOptions": { /* 基本选项 */ "target": "es5", // 指定 ECMAScript 目标 ...
- zabbix mongodb 监控添加
在zabbix 上添加mongodb的监控 由于使用的是zabbix 3.0 所有在模板里面又自己的模板名字叫:Template MongoDB 所以 客户端的配置如下 到配置文件目录 /usr/lo ...
- 可执行程序加一个dl
add_executable(forwarder app/main.cxx) TARGET_LINK_LIBRARIES(forwarder dl)
- idea运行web项目乱码
windows下idea中web项目乱码,主要原因是服务器端乱码(执行webservlet的时候,编码格式改变),导致客户端的编码格式与webservlet传递过的编码格式不一致. 前端网页的编码,通 ...