From f2a56f4ce2fccc3cd715550d5c4d9163bf9880d7 Mon Sep 17 00:00:00 2001 From: qinyingjie Date: Tue, 20 Dec 2022 08:55:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=A6=82=E8=A6=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - READ.md | 43 +++++++++++ .../springbootkwan/UserServiceImplTest.java | 71 ++++++++++++++++++- 3 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 READ.md diff --git a/.gitignore b/.gitignore index 01245e0..7ed0d6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -READ.md target/ !.mvn/wrapper/maven-wrapper.jar !**/src/main/**/target/ diff --git a/READ.md b/READ.md new file mode 100644 index 0000000..83ac6dd --- /dev/null +++ b/READ.md @@ -0,0 +1,43 @@ +## 一.说明 + +主要是SpringBoot学习 + +### 二.主要集成 + +- redis + +- mybatis-plus + +- swagger2 + +- logback + +- druid + +- @Aspect切面日志 + +- devtools热部署 + +- mapstruct dto-vo转换 + +- test测试模块 + +- mysql + +- web模块 + +- 发邮件 + + +## 三.链接 + +### 1.访问链接 + +http://localhost:8761/user/all + +### 2.swagger + +http://localhost:8761/swagger-ui.html + + + diff --git a/src/test/java/com/kwan/springbootkwan/UserServiceImplTest.java b/src/test/java/com/kwan/springbootkwan/UserServiceImplTest.java index 0508fc6..fc07814 100644 --- a/src/test/java/com/kwan/springbootkwan/UserServiceImplTest.java +++ b/src/test/java/com/kwan/springbootkwan/UserServiceImplTest.java @@ -8,6 +8,10 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + @SpringBootTest public class UserServiceImplTest { @@ -15,7 +19,7 @@ public class UserServiceImplTest { @Autowired private UserMapper userService; @Autowired - private ISendMsgHandle isSendMsgHandle; + private ISendMsgHandle emailSendMsgHandle; @Test public void queryAll() { @@ -32,6 +36,69 @@ public class UserServiceImplTest { mailInfo.setReceiver(new String[]{"qinyingjie@deepexi.com"}); mailInfo.setSubject("测试主题"); mailInfo.setContent("邮件内容"); - isSendMsgHandle.sendSimpleTextEmail(mailInfo); + emailSendMsgHandle.sendSimpleTextEmail(mailInfo); + } + + + /** + * 带html + */ + @Test + public void sendHTMLMail() { + MailInfo mailBean = new MailInfo(); + //接收人 + mailBean.setReceiver(new String[]{"qinyingjie@deepexi.com"}); + mailBean.setSubject("SpringBootMailHTML之这是一封HTML格式的邮件"); + //抄送给谁 + mailBean.setCc(new String[]{"786775527@qq.com", "286968900@qq.com"}); + StringBuilder sb = new StringBuilder(); + sb.append("

SpringBoot测试邮件HTML

") + .append("

这是一封HTML邮件...

") + .append("

时间为:" + new Date() + "

"); + mailBean.setContent(sb.toString()); + //true、false控制以普通文本发送还是以html格式发送 + emailSendMsgHandle.sendHtmlEmail(mailBean, true); + } + + @Test + void sendEmail() { + MailInfo mailBean = new MailInfo(); + mailBean.setReceiver(new String[]{"qinyingjie@deepexi.com"}); + mailBean.setSubject("SpringBootMailHTML之这是一封HTML格式的邮件"); + //抄送给谁 + mailBean.setCc(new String[]{"786775527@qq.com", "286968900@qq.com"}); + StringBuilder sb = new StringBuilder(); + sb.append("

SpringBoot测试邮件HTML

") + .append("

这是一封HTML邮件...

") + .append("

时间为:" + new Date() + "

"); + mailBean.setContent(sb.toString()); + mailBean.setAttachFileNames(new String[]{"/Users/Downloads/密码管理.xlsx", "/Users/Downloads/1635834323888.jpg"}); + emailSendMsgHandle.sendEnclosureEmail(mailBean); + } + + @Test + void sendEmail2() { + MailInfo mailBean = new MailInfo(); + mailBean.setReceiver(new String[]{"qinyingjie@deepexi.com"}); + mailBean.setSubject("SpringBootMailHTML之这是一封HTML格式的邮件"); + mailBean.setCc(new String[]{"786775527@qq.com", "286968900@qq.com"}); + StringBuilder sb = new StringBuilder(); + sb.append("

SpringBoot测试邮件HTML

") + .append("

这是一封HTML邮件...

") + .append("点击进入百度
") + //内嵌图片 + .append("

") + .append("") + .append("

时间为:" + new Date() + "

"); + mailBean.setContent(sb.toString()); + //附件 + mailBean.setAttachFileNames(new String[]{"/Users/Downloads/密码管理.xlsx", "/Users/Downloads/1635834323888.jpg"}); + //内嵌了多少张图片,如果没有,则new一个不带值的Map + Map image = new HashMap<>(); + image.put("a00000001", "/Users/Downloads/WechatIMG22.jpg"); + image.put("a00000002", "/Users/Downloads/face_1631083961355.png"); + + mailBean.setImageMap(image); + emailSendMsgHandle.sendEnclosureEmail(mailBean); } } \ No newline at end of file -- GitLab