Quantcast
Viewing all articles
Browse latest Browse all 12476

Send Email Using CQ API and custom template

Is is possible to send email using CQ API and custom template.

 

If yes how can i pass template as Subject

 

http://blogs.adobe.com/learningwem/2011/11/27/cq5-4-workflow-process-to-send-an-email-usin g-messagegateway/

 

I was followed this and able send email to the recipients .

 

But is it possible to send email CQ APi and custome email template ?

 

I was tried this using workflow process

................................................................................

public class SendEmailWorkflowProcess implements WorkflowProcess {

 

    @Reference

           private MessageGatewayService messageGatewayService;

   

    public void execute(WorkItem item, WorkflowSession wfsession,MetaDataMap metaData) throws WorkflowException {

 

 

              HtmlEmail email = new HtmlEmail();

 

         try{

               .......................

               ...................

               email.setTo( emailRecipients );

              email.setSubject( "This is subject");

              email.setHtmlMsg( "Email testing is on");

 

              String template = "/apps/cq/workflow/email/test/en.txt";

              Session session = wfsession.getSession();

 

              Resource templateRsrc = jcrResolverFactory.getResourceResolver(session).getResource(template);

 

              if (templateRsrc.getChild("file") != null) {

                 templateRsrc = templateRsrc.getChild("file");

              }

              if (templateRsrc == null) {

                 throw new IllegalArgumentException("Missing template:---------- " + template);

              }

             

              final MailTemplate mailTemplate = MailTemplate.create(templateRsrc.getPath(),

                      templateRsrc.getResourceResolver().adaptTo(Session.class));

           

                        email = mailTemplate.getEmail(StrLookup.lookup(properties,HtmlEmail.class));

      

              //Check the logs to see that messageGatewayService is not null

              log.info("messageGatewayService : " + messageGatewayService);

 

 

              messageGateway = messageGatewayService.getGateway(HtmlEmail.class);

 

 

              //Check the logs to see that messageGateway is not null

              log.info("messageGateway : " + messageGateway);

 

 

              messageGateway.send( email );

             }

          catch ( Exception e ) {

              e.printStackTrace();

              log.error( "Fatal error while sending email in workflow", e );

          }

 

 

     } 

 

 

    }

 

..............................................

 

If this is correct procedure ,

 

email = mailTemplate.getEmail(StrLookup.lookup(properties,HtmlEmail.class));

 

what value required for " properties "(properties can't be resolved)

 

All sugestions are accepted


Viewing all articles
Browse latest Browse all 12476

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>