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.
Here is video so you can watch all the steps.
Also - try on a fresh install of AEM. There may be some missing services or other mis-configured services.
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.
Now check via services (/system/console/services), find the component-id and check on the component on status.
I am seeing something like below
["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.
Via /system/console/components, search your component. Then you can see why references are not found
How can I check in /system/console why messageGatewayService.getGateway(HtmlEmail.class) gives me null??
What do you see at the component in /system/console?
There you can see the reason why a reference can't be found
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.
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.
Please check this article which discusses sending email messages using MessageGateway service:
Also, add this dependency in your POM(According to the article)
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!!