4 Replies Latest reply on Apr 22, 2013 8:20 AM by limjohnny88

    Build a Email Manager around com.day.cq.mailer

    limjohnny88 Level 1

      Hi all,

       

      I am trying to build a wrapper class around the CQ Mailer Api.

      How do I explicitly set the messageGatewayService variable, I kept getting null at it.

      @Reference

                 private MessageGatewayService messageGatewayService;

       

       

      // 1. Get the Email Template

      BundleContext bundleContext = FrameworkUtil.getBundle(ResourceResolverFactory.class).getBundleContext();

      ServiceReference<?> osgiRef = bundleContext.getServiceReference(ResourceResolverFactory.class.getName());

      ResourceResolverFactory serviceRef = (ResourceResolverFactory) bundleContext.getService(osgiRef);

      Resource templateRsrc = serviceRef.getAdministrativeResourceResolver(null).getResource(this.getEmailTemplatePath( ));

      MailTemplate mailTemplate = MailTemplate.create(templateRsrc.getPath(), templateRsrc.getResourceResolver().adaptTo(Session.class));

      this.email = mailTemplate.getEmail(StrLookup.mapLookup(this.getMailTokens()), SimpleEmail.class);

             

      // 2. Set Reciepent

      this.email.setSubject(this.getSubject());

                        this.email.setMsg(this.getMessage());

                 

                  // TO

                  for(String toEmailAddress:this.getToEmailList())

                        {

                            try {

                                      this.email.addTo(toEmailAddress);

                            }

                            catch( Exception e ) {

                 

                            }

                        }

       

       

      // 3. Send

      messageGateway = messageGatewayService.getGateway(SimpleEmail.class);

      messageGateway.send(this.email);

       

       

       

      How do i resolve it?

       

      Thanks