Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

MessageGatewayService is null

Avatar

Level 2

Hi, 

I've configured the Day Email Server with my Gmail email, which works because I am receiving workflow emails via this Gmail account, so the configuration is correct. 

But I am trying to send a campaign email newsletter and the MessageGatewayService always comes back with null.

In my class I reference the service:

@Reference
    public static MessageGatewayService messageGatewayService;

And then want to retrieve it via:

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

I found that quite some people have had the same issue but I couldn't find any solutions. 

Anyone have an idea what is going wrong?

Any help is very appreciated!

Thanks, 

Alex

1 Accepted Solution

Avatar

Correct answer by
Level 10

Just tested on 6.1

Make sure you specify the correct SMTP server, port and SMTP user and password., 

View solution in original post

4 Replies

Avatar

Level 10

For testing purposes - do you have another email server to test with. I have never had an issue with MessageServiceGateway, but I am wondering if there is an issue with GMail SMTP server. 

Avatar

Correct answer by
Level 10

Just tested on 6.1

Make sure you specify the correct SMTP server, port and SMTP user and password., 

Avatar

Level 1

I'm trying with the code in that article. I'm using AEM 6.1 and used my gmail account for smtp configuration. For me, the MessageGateway is not null but it still doesn't send email, it doesn't throw any error either. Wondering how do I debug this further?

Thanks for your help!

Avatar

Level 4

@alexandrad27705 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.