Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
smileNicky
springbootexamples
提交
0eb933a4
S
springbootexamples
项目概览
smileNicky
/
springbootexamples
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
springbootexamples
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
0eb933a4
编写于
7月 22, 2020
作者:
N
nicky
提交者:
马增群
7月 22, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
测试发送模板html邮件
上级
30a9b887
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
0 deletion
+29
-0
springboot-email/src/main/resources/templates/test.html
springboot-email/src/main/resources/templates/test.html
+11
-0
springboot-email/src/test/java/com/example/springboot/email/SpringbootEmailApplicationTests.java
...ple/springboot/email/SpringbootEmailApplicationTests.java
+18
-0
未找到文件。
springboot-email/src/main/resources/templates/test.html
0 → 100644
浏览文件 @
0eb933a4
<!DOCTYPE html>
<html
lang=
"en"
xmlns:th=
"http://www.thymeleaf.org"
>
<head>
<meta
charset=
"UTF-8"
/>
<title>
模板邮件
</title>
</head>
<body>
您好,
<span
th:text=
"${username}"
></span>
,欢迎访问我的CSDN博客:
<a
href=
"https://smilenicky.blog.csdn.net/"
>
CSDN链接
</a>
</body>
</html>
\ No newline at end of file
springboot-email/src/test/java/com/example/springboot/email/SpringbootEmailApplicationTests.java
浏览文件 @
0eb933a4
...
...
@@ -5,7 +5,11 @@ import com.example.springboot.email.service.EmailService;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.thymeleaf.TemplateEngine
;
import
org.thymeleaf.context.Context
;
import
org.thymeleaf.spring5.SpringTemplateEngine
;
import
javax.annotation.Resource
;
import
javax.mail.MessagingException
;
@SpringBootTest
...
...
@@ -13,6 +17,8 @@ class SpringbootEmailApplicationTests {
@Autowired
EmailService
emailService
;
@Resource
TemplateEngine
templateEngine
;
@Test
void
contextLoads
()
{}
...
...
@@ -63,4 +69,16 @@ class SpringbootEmailApplicationTests {
emailDto
.
setContent
(
html
);
emailService
.
sendInLineImgMail
(
emailDto
);
}
@Test
void
testSendTemplateEmail
()
throws
MessagingException
{
Context
context
=
new
Context
();
context
.
setVariable
(
"username"
,
"admin"
);
context
.
setVariable
(
"id"
,
"123456789"
);
EmailDto
emailDto
=
new
EmailDto
();
emailDto
.
setSendTo
(
"2284087296@qq.com"
);
emailDto
.
setSubject
(
"发送模板html邮件"
);
emailDto
.
setContent
(
templateEngine
.
process
(
"test"
,
context
));
emailService
.
sendHtmlMail
(
emailDto
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录