Send Email -Workflow | Community
Skip to main content
Level 9
October 16, 2015
Solved

Send Email -Workflow

  • October 16, 2015
  • 24 replies
  • 6215 views

Hello,

I would like to send email picking the template from AEM, and also dynamically adding values to the template using the workflow code. I would like to construct the "TO" list in an email dynamically, picking it up from a group of users(group A), and would like to insert a line, "URL" dynamically in the email template .txt file.

Please let me know.

Regards,

Nicole

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 JustinEd3

The problem is that you are embedding commons-email. Don't do this. Your bundle needs to import org.apache.commons. 

24 replies

Level 9
October 16, 2015

Scott, 

I tried using message gateway service to send out an email, in my custom workflow process step, but keep getting the error, a NPE, i have keyed in smtp port and username etc in CQ mail service configuration in system console. I see people posting issues on the same, please help me with this.

Code:

@Reference
private MessageGatewayService messageGatewayService;

     ArrayList<InternetAddress> emailRecipients = new ArrayList<InternetAddress>();

public void execute(WorkItem item, WorkflowSession session,

    MetaDataMap metaData) throws WorkflowException {

HtmlEmail email = new HtmlEmail();

      emailRecipients.add(new InternetAddress("email") );
      email.setTo( emailRecipients );
      email.setSubject( "This is subject");
      email.setHtmlMsg( "Email testing");

Error:

messageGatewayService : com.day.cq.mailer.impl.CqMailingService@c14701
messageGateway : null
Fatal error while sending email in workflowjava.lang.NullPointerException

smacdonald2008
Level 10
October 16, 2015

If OOTB does not address your needs -- then yes - you are correct - a custom workflow step is the way to go. Remember that a custom workflow step is just like any other OSGi bundle which is Java. So there is not much you cannot accomplish. If you want to get CQ users for you custom workflow step -- you can use the CQ com.day.cq.security.UserManager. API. To learn how to work with this API, see http://scottsdigitalcommunity.blogspot.ca/2013/07/using-ajax-requests-to-display-adobe-cq.html

Level 9
October 16, 2015

No Scott, I am trying to create a workflow step mocking the Send Email functionality, Since not all my requirements might be met by OOTB component. 

Level 9
October 16, 2015

Justin, 

I wonder if this has been missed out in Documentation , but if one needs to send out email from AEM, on start up -Djava.net.preferIPv4Stack=true needs to be added.

Wish it was known earlier, Would be helpful for others trying to crack this issue. Thanks for help and patience ,