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. ...
随机推荐
- Ruby初见
一. 简介 Ruby,一种简单快捷的面向对象(面向对象程序设计)脚本语言,在20世纪90年代由日本人松本行弘(Yukihiro Matsumoto)开发,遵守GPL协议和Ruby License. 二 ...
- layui自定义插件citySelect 省市区三级联动选择
省市区三级菜单联动插件 citySelect.js /** * @ name : citySelect 省市区三级选择模块 * @ Author: aggerChen * @ version: 1.0 ...
- python-redis-订阅和发布
发布:redishelper.py import redis class RedisHelper: def __init__(self): self.__conn = redis.Redis(host ...
- Codeforces 1194B. Yet Another Crosses Problem
传送门 直接枚举填满哪一行,然后看看这一行填满以后哪一列最小 这个预处理一下 $cnt[i]$ 表示初始时第 $i$ 列有几个位置填满就可以做到 $O(m)$ 对于所有情况取个 $min$ 就是答案, ...
- js三级内联
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- mac 下安装mysql8.0
有两种安装方式,一种是安装包安装,官网下载安装包,mysql8.0下载.mysql5.7安装: 这里记录brew安装: 1.brew uninstall mysql 卸载原有的: 2.brew ins ...
- H5的video标签在网页上播放MP4视频时只有声音没有画面
最近做一个项目时,发现mp4文件播放时没有图像,只有声音,代码检查了N次,都没有问题,就算是直接使用网上的实例代码,也只能播放实例视频,mp4文件绝对路径,相对路径也都试了,还是不能播放我的mp4. ...
- js介绍及语法结构
javaScript它是一门动态的,弱类型的,解释型面向Web的编程语言.虽然名字里有Java但其它与Java无关.它可以用来增强页面动态效果,实现页面与用户之间的实时,动态交互. javascrip ...
- electron builder 打包多个第三方依赖的软件
背景 在实际的开发过程中,我们最后打包生成的exe.会依赖一些第三方的软件,或者说是一些系统的环境,比如 .net framework vc++ 等,这些环境不能依赖客户的环境,所以最好的做法是在打包 ...
- linux svn 安装
1.环境centos6.4 2.安装svnyum -y install subversion 3.配置 建立版本库目录mkdir /var/www/svndata svnserve -d -r /va ...