【发布时间】:2015-10-13 17:13:19
【问题描述】:
我目前正在使用带有 Spring MVC 和 Freemarker 的 Spring Boot 1.2.5 进行 Web 开发。
我想使用 freemarker 模板编写 html 邮件正文,该邮件正文将与 JavaMailSender 一起发送。
邮件将由其中一项服务组成和发送。
实现它的最简单设置是什么?
【问题讨论】:
标签: spring-boot html-email freemarker
我目前正在使用带有 Spring MVC 和 Freemarker 的 Spring Boot 1.2.5 进行 Web 开发。
我想使用 freemarker 模板编写 html 邮件正文,该邮件正文将与 JavaMailSender 一起发送。
邮件将由其中一项服务组成和发送。
实现它的最简单设置是什么?
【问题讨论】:
标签: spring-boot html-email freemarker
其实以自定义方式使用模板还是比较简单的(可以从spring boot freemarker自动配置器中注入freemarkers配置):
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
//skipped class etc for clarity
@Autowired
private final Configuration freemarkerConfiguration;
public void process() throws IOException, TemplateException {
final Template template = freemarkerConfiguration.getTemplate("/path/to/template.ftl");
final Map<String, Object> params = new HashMap<>();
params.put("param1", 1);
params.put("param2", 2);
template.process(params, /* use writer to which body will be written */);
}
【讨论】: