提交 0eb933a4 编写于 作者: N nicky 提交者: 马增群

测试发送模板html邮件

上级 30a9b887
<!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
......@@ -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.
先完成此消息的编辑!
想要评论请 注册