简体   繁体   English

如何在Liferay中将freemarker电子邮件模板作为电子邮件传递?

[英]How to pass freemarker email template as email in Liferay?

I have used Freemarker for creating a template which I will be using to send as email. 我已经使用Freemarker创建了一个模板,该模板将用作电子邮件发送。 Here is the snippet of the parameters that i wish to include in the template. 这是我希望包含在模板中的参数片段。 Iam using java.. Iam使用Java ..

//use freemarker Configuration config = new Configuration(); //使用freemarker配置config = new Configuration(); config.setTemplateLoader(new ClassTemplateLoader(getClass(), "/")); 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();

This is tested and it successfully created a template in the specified folder. 经过测试,它成功在指定文件夹中创建了模板。 All I want to know is how do i pass the template that is generated as a parameter while sending mail? 我只想知道如何在发送邮件时传递作为参数生成的模板?

I am sending email as follows in Liferay How should I pass the template as a parameter while sending mail? 我将在Liferay中发送电子邮件,如下所示:发送邮件时如何传递模板作为参数?

You're writing to System.out 您正在写System.out

    // Console output
    Writer out = new OutputStreamWriter(System.out);
    template.process(data, out);
    out.flush();

You can write to a String: 您可以写一个字符串:

    StringWriter out = new StringWriter();
    template.process(data, out);
    String finishedMessage = out.toString();

or pass any other writer to the process() method. 或将其他任何编写器传递给process()方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM