package com.neo.service; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.Context; /** * Created by summer on 2017/5/4. */ @RunWith(SpringRunner.class) @SpringBootTest public class MailServiceTest { @Autowired private MailService mailService; @Autowired private TemplateEngine templateEngine; @Test public void testSimpleMail() throws Exception { mailService.sendSimpleMail("ityouknow@126.com","test simple mail"," hello this is simple mail"); } @Test public void testHtmlMail() throws Exception { String content="\n" + "\n" + "

hello world ! 这是一封html邮件!

\n" + "\n" + ""; mailService.sendHtmlMail("ityouknow@126.com","test simple mail",content); } @Test public void sendAttachmentsMail() { String filePath="D:\\Log\\TaxCard.log"; mailService.sendAttachmentsMail("ityouknow@126.com", "主题:带附件的邮件", "有附件,请查收!", filePath); } @Test public void sendInlineResourceMail() { String rscId = "neo006"; String content="这是有图片的邮件:"; String imgPath = "C:\\Users\\ityou\\Pictures\\logo\\smilef.png"; mailService.sendInlineResourceMail("ityouknow@126.com", "主题:这是有图片的邮件", content, imgPath, rscId); } @Test public void sendTemplateMail() { //创建邮件正文 Context context = new Context(); context.setVariable("id", "006"); String emailContent = templateEngine.process("emailTemplate", context); mailService.sendHtmlMail("ityouknow@126.com","主题:这是模板邮件",emailContent); } }