我已经使用 Freemarker 创建了一个模板,我将使用该模板作为电子邮件发送。 这是我希望包含在模板中的参数片段。 我正在使用java..
//使用freemarker 配置config = new Configuration(); config.setTemplateLoader(new ClassTemplateLoader(getClass(), "/"));
Template template = config.getTemplate("helloworld.ftl");
// Build the data-model
Map<String, Object> data = new HashMap<String, Object>();
data.put("message", "Hello!! You have got a new approval mail!");
//List parsing
List<String> mailDetails = new ArrayList<String>();
mailDetails.add(fromAddress);
mailDetails.add(fromName);
mailDetails.add(toAddress);
mailDetails.add(toName);
mailDetails.add(subject);
mailDetails.add(body);
data.put("mailDetails", mailDetails);
// Console output
Writer out = new OutputStreamWriter(System.out);
template.process(data, out);
out.flush();
这已经过测试,并成功在指定文件夹中创建了模板。 我想知道的是如何传递发送邮件时作为参数生成的模板?
我在 Liferay 中发送电子邮件如下 发送邮件时如何将模板作为参数传递?
最佳答案
您正在写入System.out
// Console output
Writer out = new OutputStreamWriter(System.out);
template.process(data, out);
out.flush();
您可以写入字符串:
StringWriter out = new StringWriter();
template.process(data, out);
String finishedMessage = out.toString();
或将任何其他编写器传递给 process()
方法。
关于java - 如何在 Liferay 中将 freemarker 电子邮件模板作为电子邮件传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15778836/