We are writing a HELPX article to show how to use the MessageServiceGateWay API to send emails based on a template. And how to populate it via a MAP object that contains key/values. But as i stated in my first response - to use a custom EMail template in a workflow - you need to write a custom WORKFLOW Step then Java such as:
//Sends HTML email based on an AEM Template
private void SendHHTMLEmail(SlingHttpServletRequest request)
{
try
{
Map myMap = new HashMap() ;
myMap.put("host.prefix","Foo"); //use a map entry for each variable to populate
//Declare a MessageGateway service
MessageGateway<HtmlEmail> messageGateway;
//Specify the EMail template to use in email
String template ="/etc/notification/email/html/com.day.cq.collab.forum/en.txt";
Resource templateRsrc = request.getResourceResolver().getResource(template);
String path = templateRsrc.getPath();
MailTemplate mailTemplate = MailTemplate.create(templateRsrc.getPath(), templateRsrc.getResourceResolver().adaptTo(Session.class));
HtmlEmail email = mailTemplate.getEmail(StrLookup.mapLookup(myMap), HtmlEmail.class);
email.addTo("scottm@adobe.com");
email.setSubject("AEM Email Template");
email.setFrom("smacdonald2006@hotmail.com");
//Inject a MessageGateway Service and send the message
// messageGateway = messageGatewayService.getGateway(Email.class);
messageGateway = this.messageGatewayService.getGateway(HtmlEmail.class);
// gateway.send(email);
// Check the logs to see that messageGateway is not null
messageGateway.send((HtmlEmail) email);
// messageGateway.send((Email) email);
}
catch (Exception e)
{
log.info(e.getMessage()) ;
}
}