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:
@component(service = Servlet.class,
property = {
"sling.servlet.methods=" + "GET",
"sling.servlet.paths =" + "/bin/test/email-content-report"})
public class ContentReportServlet extends SlingAllMethodsServlet {
@reference
MessageGatewayService messageGatewayService;
@Override
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
Solved! Go to Solution.
Views
Replies
Total Likes
use same OSGI annotation for Reference also.
Is the MessageGatewayService is active?
can you check that in configMgr.
Also make sure the annotations are used properly
keep some log statements to get more details and also can we get Service class code also?
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
use same OSGI annotation for Reference also.
That worked, thanks for the help!
Views
Likes
Replies