MessageGateway is | Community
Skip to main content
Level 2
March 11, 2024
Solved

MessageGateway is

  • March 11, 2024
  • 1 reply
  • 990 views

Hi 
I am created an email servlet in AEM and it works fine when I tested it on my local 4502,

but when I test this servlet on company DEV environment, the messageGateway is always null

MessageGateway<HtmlEmail> messageGateway = messageGatewayService.getGateway(HtmlEmail.class);

 Here's my code:

@8220494(service = Servlet.class, property = { "sling.servlet.methods=" + "GET", "sling.servlet.paths =" + "/bin/test/email-content-report"}) public class ContentReportServlet extends SlingAllMethodsServlet { @3214626 MessageGatewayService messageGatewayService; @9944223 protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) { try { MessageGateway<HtmlEmail> messageGateway = messageGatewayService.getGateway(HtmlEmail.class); if(messageGateway != null) { HtmlEmail email = new HtmlEmail(); email.setCharset("utf-8"); email.addTo(recipientemail); email.setFrom("noreply@test.ca"); email.setSubject("Email Testing"); email.setHostName("mailgateway.uk.fid-intl.com"); email.setSmtpPort(587); email.setSSLOnConnect(false); email.setHtmlMsg("Test message"); ByteArrayDataSource dataSource = new ByteArrayDataSource(byteStream.toByteArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); email.attach(dataSource, "filename.xlsx", "ContentReport", HtmlEmail.ATTACHMENTS); messageGateway.send(email); } } catch (Exception e) { log.error("Error occurred while sending report by email: {}", e.getMessage(), e); } } }

I found a few old posts with the same issue saying that I need to change the day cq mail service, I tried that but still doesn't work
here's the day cq mail service on my local

Here's the day cq mail service for the dev environment

Please advise. 
Thank you

 

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 SureshDhulipudi

use same OSGI annotation for Reference also.

import org.osgi.service.component.annotations.Reference;
That is the issue. instead of using from Felix.

1 reply

SureshDhulipudi
Community Advisor
Community Advisor
March 11, 2024

Is the MessageGatewayService is active?

can you check that in configMgr.

Also make sure the annotations are used properly 

@3214626

 

@8220494

 

keep some log statements to get more details and also can we get Service class code also?

HanLAuthor
Level 2
March 11, 2024

Hi Suresh
For those two annotations, I am using:
import org.osgi.service.component.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
In the log, an exception was thrown 

java.lang.NullPointerException: null

at

 

MessageGateway<HtmlEmail> messageGateway = messageGatewayService.getGateway(HtmlEmail.class);

 

I tried to search MessageGatewayService in configMgr in both my local and DEV environments, can't find anything.

May I ask, what Service class do you mean?

Thank you

SureshDhulipudi
Community Advisor
SureshDhulipudiCommunity AdvisorAccepted solution
Community Advisor
March 11, 2024

use same OSGI annotation for Reference also.

import org.osgi.service.component.annotations.Reference;
That is the issue. instead of using from Felix.