SpringBoot-Thymeleaf发送模板带附件邮件
2017-09-20 11:24
821 查看
SpringBoot-Thymeleaf发送模板带附件邮件
自个学习笔记不喜勿喷
@RunWith(SpringRunner.class) @SpringBootTest public class SpringBootEmailApplicationTests { @Value("${spring.mail.username}") private String fromEmailAddr; @Autowired private JavaMailSender javaMailSender; @Autowired private TemplateEngine templateEngine; /** * @throws MessagingException * @Title: sendHtmlEmail * @Description: 发送thymeleaf模板邮件 * @return void * @throws */ @Test public void sendHtmlEmail() throws MessagingException { MimeMessage mailMessage = javaMailSender.createMimeMessage(); //开启带附件true MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage, true); IContext context = new Context(); //获取模板html代码 String process = templateEngine.process("index", context); try { messageHelper.setFrom(fromEmailAddr); messageHelper.setTo("112121@qq.com"); messageHelper.setSubject("SpringBootThymeleaf模板邮件"); messageHelper.setText(process, true); FileSystemResource avatar = new FileSystemResource( new File("F:\\workspace\\SpringBootEmail\\src\\main\\resources\\templates\\img\\bappy.jpg")); //<img src="cid:avatar" /> messageHelper.addInline("avatar", avatar); } catch (MessagingException e) { // TODO Auto-generated catch block e.printStackTrace(); } javaMailSender.send(mailMessage); } }
有一个问题,那就是不能发送外嵌样式的邮件,只能将样式弄进模板文件里。
相关文章推荐
- spring- boot 发送邮件接口+freemarker视图模板引擎
- spring使用模板发送邮件及附件笔记
- spring boot 发送邮件带附件出现Not in multipart mode - create an appropriate MimeMessageHelper错误
- SpringBoot + Thymeleaf实现邮件发送功能
- spring使用模板发送邮件及附件笔记
- springboot 普通发送邮件 和 freemarker模板发送邮件
- java 利用spring JavaMailSenderImpl发送邮件,支持普通文本、附件、html、velocity模板
- Spring 4 使用Freemarker模板发送邮件&添加附件
- spring使用FreeMarker模板发送邮件及附件笔记
- springboot集成JMS含附件邮件发送
- Spring 4 使用Freemarker模板发送邮件&添加附件
- java 利用spring JavaMailSenderImpl发送邮件,支持普通文本、附件、html、velocity模板
- spring使用模板发送邮件及附件笔记
- Spring Boot 使用465端口发送邮件
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- spring boot 发送邮件
- yx: SpringBoot发送邮件功能
- 集成springboot+thymeleaf+redis+加密框架+异常邮件提醒等技术的开源项目
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- spring boot发送邮件