Hi,
I have a requirement for sending a Mail from AEM using email templates. I have to hit a aem servlet from external server with required parameters and then construct the email and using aem mail templates and cq mail service shoot the mail. Could anyone please help me with it.
Solved! Go to Solution.
Views
Replies
Total Likes
Try to use HtmlEmail.class .
I hope this code will help you.
MessageGateway<HtmlEmail> messageGateway = messageGatewayService.getGateway(HtmlEmail.class);
HtmlEmail email = new HtmlEmail();
email = mailTemplate.getEmail(StrLookup.mapLookup(emailProperties), HtmlEmail.class);
List<InternetAddress> emailRecipients = new ArrayList<InternetAddress>();
emailRecipients.add(new InternetAddress(request.getParameter("email")));
email.setTo(emailRecipients);
messageGateway.send(email);
Views
Replies
Total Likes
Here is a community article that shows how to send email using the MessageGateway API:
https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/day/cq/mailer/MessageGateway.html
Article:
https://helpx.adobe.com/experience-manager/using/creating-custom-aem-workflow-steps.html
The email is sent as part of a custom workflow. Also - its only a text based email - it does not use a template.
See this older community thread for good information about sending with a template:
Views
Replies
Total Likes
I'm a big fan of the ACS Commons Email API (link below).
You can supply an email template and pass in key/value pairs to replace tokens within the template.
http://adobe-consulting-services.github.io/acs-aem-commons/features/email-api.html
Views
Replies
Total Likes
Create a custom sling servlet to handle the HTTP POST/GET operation. For information on creating sling servlets for AEM - see:
https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html
See this older community thread for details on email/templates:
Views
Replies
Total Likes
In that i am having issue in the line
Email email = mailTemplate.getEmail(StrLookup.mapLookup(emailParams), emailClass);
I am getting
27.07.2015 18:56:08.227 *ERROR* [127.0.0.1 [1438003568172] GET /bin/servlet/mailservlet HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught Throwable
java.lang.LinkageError: loader constraint violation: when resolving method "com.day.cq.commons.mail.MailTemplate.getEmail(Lorg/apache/commons/lang/text/StrLookup;Ljava/lang/Class;)Lorg/apache/commons/mail/Email;" the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) of the current class, com/aircanada/aem/email/impl/EmailServiceImpl, and the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for resolved class, com/day/cq/commons/mail/MailTemplate, have different Class objects for the type s/lang/text/StrLookup;Ljava/lang/Class;)Lorg/apache/commons/mail/Email; used in the signature
at com.aircanada.aem.email.impl.EmailServiceImpl.getEmail(EmailServiceImpl.java:152)
at com.aircanada.aem.email.impl.EmailServiceImpl.sendEmail(EmailServiceImpl.java:109)
at com.aircanada.aem.email.impl.EmailServiceImpl.sendEmail(EmailServiceImpl.java:86)
at com.aircanada.aem.email.EmailSevlet.doGet(EmailSevlet.java:66)
error
Please help me with that.
Thanks,
Tushar
Views
Replies
Total Likes
Are you following the code from the 1st link:
http://adobe-consulting-services.github.io/acs-aem-commons/features/email-api.html
Views
Replies
Total Likes
Yes I am following that, as it matched my requirement of sending a mail using a template.
Views
Replies
Total Likes
Did you install the ACS Commons package from here
Views
Replies
Total Likes
Try to use HtmlEmail.class .
I hope this code will help you.
MessageGateway<HtmlEmail> messageGateway = messageGatewayService.getGateway(HtmlEmail.class);
HtmlEmail email = new HtmlEmail();
email = mailTemplate.getEmail(StrLookup.mapLookup(emailProperties), HtmlEmail.class);
List<InternetAddress> emailRecipients = new ArrayList<InternetAddress>();
emailRecipients.add(new InternetAddress(request.getParameter("email")));
email.setTo(emailRecipients);
messageGateway.send(email);
Views
Replies
Total Likes
No I didn't take this package, in my package it had all the java code for sending email
Views
Replies
Total Likes
I am using this URL for the package
https://github.com/Adobe-Consulting-Services/acs-aem-commons
Views
Replies
Total Likes
What is the "emailProperties" , is it a MAP containing all the params. Also I have used HtmlEmail.class, still it gives the same error
Views
Replies
Total Likes
tushark60575350 wrote...
What is the "emailProperties" , is it a MAP containing all the params. Also I have used HtmlEmail.class, still it gives the same error
Yes, it's my map parameters.
I got values from Front end.
Views
Replies
Total Likes
Hi,
I am using ACS commons for sending the email. Following the below link:
http://adobe-consulting-services.github.io/acs-aem-commons/features/email-api.html
But i am getting the error as below at
Email email = mailTemplate.getEmail(StrLookup.mapLookup(emailParams), emailClass);
ERROR LOGS:
rg.apache.commons.mail.EmailException: Missing final '@domain'
at org.apache.commons.mail.Email.createInternetAddress(Email.java:605)
at org.apache.commons.mail.Email.addCc(Email.java:806)
at org.apache.commons.mail.Email.addCc(Email.java:789)
at org.apache.commons.mail.Email.addCc(Email.java:769)
at com.day.cq.commons.mail.MailTemplate.getEmail(MailTemplate.java:170)
at com.adobe.acs.commons.email.impl.EmailServiceImpl.getEmail(EmailServiceImpl.java:211)
at com.adobe.acs.commons.email.impl.EmailServiceImpl.sendEmail(EmailServiceImpl.java:129)
at com.adobe.acs.commons.email.impl.EmailServiceImpl.sendEmail(EmailServiceImpl.java:102)
at com.gmf.cms.core.servlets.SendEmailServlet.doPost(SendEmailServlet.java:50)
Is there a fix for this?
Thanks in advance!
Views
Replies
Total Likes
Views
Like
Replies