MessageGateway is coming as null | Community
Skip to main content
Level 2
March 3, 2017
Solved

MessageGateway is coming as null

  • March 3, 2017
  • 10 replies
  • 4378 views

Hi Friends,

I am trying to send email in participant step. I have written a email service which uses the Message Gateway to send emails.

But MessageGateway<Email> messageGateway = this.messageGatewayService.getGateway(Email.class); this line is giving messageGateway as null.

I went through a number of posts and everywhere it is mentioned that if the SMTP details are not mentioned properly in Day Cq Mail service then it comes as null.

But I have configured it properly because if I select the senEmail checkbox in the dynamic step then AEM is able to send default emails using this. So I am sure SMTP is not something which can be at fault. Do we need something else also so that the messageGateway doesnot come as null. I am using AEM 6.1 SP3.

Thanks,

Tushar

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 smacdonald2008

Here is video so you can watch all the steps. 

https://www.youtube.com/watch?v=9Ztc9hBbrwg&feature=youtu.be

Also - try on a fresh install of AEM. There may be some missing services or other mis-configured services. 

10 replies

Ratna_Kumar
Level 10
March 3, 2017

Hi Tushar,

Please check this article which discusses sending email messages using MessageGateway service:
//https://helpx.adobe.com/experience-manager/using/creating-custom-aem-workflow-steps.html

Also, add this dependency in your POM(According to the article)

<dependency> 
    <groupId>com.day.cq</groupId>
    <artifactId>cq-mailer</artifactId>
    <version>5.6.2</version> 
    <scope>provided</scope> 
</dependency>

It worked for me many times and you need to configure Email properly in configuration manager.

In order to configure properly, you need to check this excellent article which tells how to configure the email:: http://versatileankur.blogspot.in/2016/04/mailing-issue-in-aem-with-gmail-smtp.html

Hope this helps!!

~ Ratna.

Level 2
March 3, 2017

I have added that dependency already, also as I have mentioned earlier if I use aem's send email functionality in the participant step the default email does get generated which ascertains the fact that my SMTP details are working fine.

The only issue I am facing is the Message Gateway coming as null. I wanted to know is this a bug with AEM 6.1 sp2 that we cannot send email through our customized way i.e. using MessageGateway.

Thanks for any help.

Level 2
March 4, 2017

Hi Scott,

I have tried even that and still the MessageGateway comes null. I know the smtp config is correct as the default emails from Aem are generating fine.

Feike_Visser1
Adobe Employee
Adobe Employee
March 4, 2017

What do you see at the component in /system/console?

There you can see the reason why a reference can't be found

Level 2
March 6, 2017

How can I check in /system/console why messageGatewayService.getGateway(HtmlEmail.class) gives me null??

Feike_Visser1
Adobe Employee
Adobe Employee
March 6, 2017

Via /system/console/components, search your component. Then you can see why references are not found

Level 2
March 6, 2017

Hi,

I am seeing something like below

     
Reference messageGatewayService

["Unsatisfied","Service Name: com.day.cq.mailer.MessageGatewayService","Cardinality: 1..1","Policy: static","Policy Option: reluctant","No Services bound"]

Could you please let me know why this could be coming like this.

Thanks,

Tushar

Feike_Visser1
Adobe Employee
Adobe Employee
March 6, 2017

Now check via services (/system/console/services), find the component-id and check on the component on status.

smacdonald2008
smacdonald2008Accepted solution
Level 10
March 6, 2017

Here is video so you can watch all the steps. 

https://www.youtube.com/watch?v=9Ztc9hBbrwg&feature=youtu.be

Also - try on a fresh install of AEM. There may be some missing services or other mis-configured services. 

anjali_biddanda
Level 4
June 9, 2021

Restarting the com.day.cq.cq-mailer bundle in the environment was the solution that worked for me.

The MessageGatewayService contains a hashSet of gateways. If you delete or move your Day CQ Mail Service configuration, a new gateway is added to the hashSet. The messageGatewayService.getGateway() only retrieves one DefaultMailService from the hashSet, and it could be one with cfg null inside, although there exists one configured correctly. Only way to clean this up is by restarting the bundle. 

Any subsequent updates to theDefaultMailService config work fine. This only happens when you delete/move your config in your environment.