Email html template

Hi there,

is there a way to create own email template with html structure with using ftl file?
Then into that template I would like to append content (simple text) from cms and send it to customer as a confirmation email.

Thanks,
Michal

Hi,

Yes of course. You can use any templating engine you like, have it parse your template and take whatever action. I would guess this would be in response to an action on the site like a form submit? Most likely do it in the doAction method in that case. Or is it another flow you are thinking of?

If you have an enterprise license and are using eforms then see:

Yes i need it for form submit action but as a confirmation

is there a way to do it here?

Follow the link I posted, it contains exactly what you want. It’s called the Mail Form Data Behavior.

Jasper, I’ve looked at your link and it refers to emailing form data to a specified email address.

What we are looking to do is send a confirmation email (covered by Submission Confirmation Behavior) to the user that submitted the form. There is no field on that plugin to enter a template, although the documentation suggests a template can be added to the project.

Are you suggesting we can add a template to Mail Form Behavior and it will be picked up by Submission Confirmation Behavior?

hmm…you are right about that. Sorry, didn’t read properly. You need the submission behavior, but that also supports templating. It should work the same way as the Mail Form Data behavior. The documentation implies it is possible but doesn’t really explain it. But the functionality for processing the template is in a shared abstract parent class.

Hi,

I’ve just had a look at the code. I think it’s possible to use your own email template with the Submission Confirmation behavior.
Basically both Submission Confirmation Behavior [1] and Mail Form Data Behavior [2] extend the same parent class, AbstractMailBehavior, which allows the following:

  • If the specific HST component configuration includes “eforms-body-html” parameter (string), containing a full freemarker or velocity template source, then it uses the parameter value when generating email body message. The parameter is for both plain text and html format.

  • Otherwise, it falls back to the following default templates (defined in FreemarkerParser.java):

    public static final String DEFAULT_TEXT_TEMPLATE = “com/onehippo/cms7/eforms/hst/templates/email/eforms_text.ftl”;
    public static final String DEFAULT_HTML_TEMPLATE = “com/onehippo/cms7/eforms/hst/templates/email/eforms_html.ftl”;

    So, for example, if you put a custom file at site/src/main/resources/com/onehippo/cms7/eforms/hst/templates/email/eforms_html.ftl to shadow the default one, you will change the default template for html e-mail message. But this shadowing will affect both [1] and [2]. Therefore, component parameter configuration will be safer.

Regards,

Woonsan

[1] https://www.onehippo.org/library/enterprise/enterprise-features/enterprise-forms/pluggable-behavior-items/submission-confirmation-behavior.html
[2] https://www.onehippo.org/library/enterprise/enterprise-features/enterprise-forms/pluggable-behavior-items/mail-form-data-behavior.html

1 Like

Thanks Woonsan! Using the eforms-body-html parameter worked.