package com.kwan.springbootkwan; import com.kwan.springbootkwan.entity.MailInfo; import com.kwan.springbootkwan.entity.User; import com.kwan.springbootkwan.mapper.UserMapper; import com.kwan.springbootkwan.service.ISendMsgHandle; import com.kwan.springbootkwan.utils.RedisIdWorker; 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; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @SpringBootTest public class UserServiceImplTest { @Autowired private UserMapper userService; @Autowired private ISendMsgHandle emailSendMsgHandle; @Test public void queryAll() { User user = userService.selectById(1); System.out.println(user); } /** * 发邮件 */ @Test void sendSimpleTextEmail() { MailInfo mailInfo = new MailInfo(); mailInfo.setReceiver(new String[]{"qinyingjie@deepexi.com"}); mailInfo.setSubject("测试主题"); mailInfo.setContent("邮件内容"); 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("
这是一封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("这是一封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("这是一封HTML邮件...
") .append("点击进入百度时间为:" + new Date() + "
"); mailBean.setContent(sb.toString()); //附件 mailBean.setAttachFileNames(new String[]{"/Users/Downloads/密码管理.xlsx", "/Users/Downloads/1635834323888.jpg"}); //内嵌了多少张图片,如果没有,则new一个不带值的Map Map