Using email template in AEM form
Hi,
I am working on a form where on submit, I have to send an email using email template. I am writing this custom action since I have to write some more business logic further (Like attaching a doc, reading an XML etc). But I am stuck in this basic code just to send the mail first.
Map<String, String> mailTokens = new HashMap<String, String>();
mailTokens.put("subject", "Testing the mail template");
mailTokens.put("thanks", "Thanks");
mailTokens.put("author", "Team.");
mailTokens.put("message","This is the message");
Resource templateRsrc = slingRequest.getResourceResolver().getResource("/apps/custom_submit_action/store_and_email/temp.txt");MailTemplate mailTemplate = MailTemplate.create(templateRsrc.getPath(), templateRsrc.getResourceResolver().adaptTo(Session.class));
HtmlEmail email = mailTemplate.getEmail(StrLookup.mapLookup(mailTokens), HtmlEmail.class); //Line 61
email.addTo("MyEmailAddress");
email.send();
I am getting following exceptions
com.adobe.aemds.guide.service.GuideException: An exception occurred processing JSP page /apps/custom_submit_action/store_and_email/post.POST.jsp at line 61 at com.adobe.aemds.guide.servlet.GuideSubmitServlet.doPost(GuideSubmitServlet.java:254) at org.apache.sling.api.servlets.SlingAllMethodsServlet.mayService(SlingAllMethodsServlet.java:149) .......
Caused by: org.apache.sling.api.SlingException: An exception occurred processing JSP page /apps/custom_submit_action/store_and_email/post.POST.jsp at line 61 at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspExceptionInternal(JspServletWrapper.java:683) at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:608) at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:525) at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:449) at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:284) at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:102) at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:536) at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:361) ... 155 more Caused by: org.apache.commons.mail.EmailException: Invalid message supplied at org.apache.commons.mail.HtmlEmail.setMsg(HtmlEmail.java:177) at com.day.cq.commons.mail.MailTemplate.getEmail(MailTemplate.java:147) at org.apache.jsp.apps.custom_005fsubmit_005faction.store_005fand_005femail.post_POST_jsp._jspService(post_POST_jsp.java:305) at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:502) ... 160 more