MessageGateway is coming as null | Community
Skip to main content
Level 2
Mar 3, 2017 6:09 AM UTC
Solved

MessageGateway is coming as null

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.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Mar 6, 2017 5:59 PM UTC

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

anjali_biddanda
Level 4
Jun 9, 2021 7:32 AM UTC

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.

Translate
smacdonald2008
smacdonald2008Accepted solution
Level 10
Mar 6, 2017 5:59 PM UTC

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. 

Translate
Feike_Visser1
Employee
Mar 6, 2017 12:38 PM UTC

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

Translate
Level 2
Mar 6, 2017 12:26 PM UTC

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

Translate
Feike_Visser1
Employee
Mar 6, 2017 12:14 PM UTC

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

Translate
Level 2
Mar 6, 2017 9:04 AM UTC

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

Translate
Feike_Visser1
Employee
Mar 4, 2017 1:16 PM UTC

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

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

Translate
Level 2
Mar 4, 2017 8:05 AM UTC

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.

Translate
Level 2
Mar 3, 2017 11:01 AM UTC

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.

Translate
Ratna_Kumar
Level 10
Mar 3, 2017 10:41 AM UTC

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.

Translate