Introduction
This blog describes how to create e-mail template in Alfresco and use it for sending e-mail.
Template
E-mail templates are kept in folder Company Home/Data Dictionary/Email Templates
, but in general they can be kept in any folder. Let’s assume, that in our template we want to use some variables, which values will be passed during invocation of e-mail action. Our template is saved in Company Home/Data Dictionary/Email Templates/sample_template.ftl
and is defined as follows:
<html>
<head></head>
<body>
Hello ${firstName}!
</body>
</html>
Variable ‘firstName’ should be replaced with the name of user the message is send to.
E-mail send action
We will invoke e-mail sending action using Alfresco JavaScript API:
var mail = actions.create("mail");
// List of comma separated user names e-mail should be send to
mail.parameters.to_many = admin;
// Subject of e-mail
mail.parameters.subject = "Sample e-mail";
// Map of variables to be used in the template
var map = new Object();
map["firstName"] = person.properties["cm:firstName"];
// Path to template to be used in e-mail
mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/sample_template.ftl");
// Map of variables to be used in the template
mail.parameters.template_model = map;
// Execute e-mail send action
mail.execute(companyhome);