Sending Email By AEM | Community
Skip to main content
Level 2
October 16, 2015
Solved

Sending Email By AEM

  • October 16, 2015
  • 13 replies
  • 12377 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by narayanank84409

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);

13 replies

Level 8
October 16, 2015

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

smacdonald2008
Level 10
October 16, 2015

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: 

https://forums.adobe.com/thread/1107034?start=0&tstart=0

March 30, 2017

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!