Expand my Community achievements bar.

com.day.cq.mailer.MailingException: Invalid mail service configuration.

Avatar

Level 2
Hi,
 
We are using the MessageGatewayService to send custom email notifications within a workflow. I've configured the SMTP details correctly and verified them in the Day CQ Mail Service configuration in ConfigMgr. However, I encounter an "Invalid mail service configuration" error when sending emails. 
 
While debugging the code, I noticed that all values are null within MessageGateway<HtmlEmail> messageGateway = messageGatewayService.getGateway(HtmlEmail.class);.The issue resolves when I restart the instance or stop and start the "Day Communique 5 Mailer" bundle (com.day.cq.cq-mailer).
 
We are using AEM 6.5 with Service Pack 6.5.17. 
 
Any help is greatly appreciated.
 
Caused by: com.day.cq.mailer.MailingException: Invalid mail service configuration.
    at com.day.cq.mailer.impl.DefaultMailService.send(DefaultMailService.java:300) [com.day.cq.cq-mailer:5.14.3.B0006]
    at com.day.cq.mailer.impl.DefaultMailService.send(DefaultMailService.java:50) [com.day.cq.cq-mailer:5.14.3.B0006]
 
Topics

Topics help categorize Community content and increase your ability to discover relevant content.

7 Replies

Avatar

Community Advisor

@Divya_T13 

 

The issue has been reported over multiple threads with a solution to restart the bundle. 

 

Somehow we are not facing this issue.

Our config is placed under /apps/system/config/com.day.cq.mailer.DefaultMailService.config

 

In the old format

# Configuration created by Apache Sling JCR Installer
debug.email=B"true"
smtp.starttls=B"false"
oauth.flow=B"false"
smtp.host="abc.smail.com"
smtp.ssl=B"false"
from.address="abc@def.com"
smtp.port=I"25"
smtp.password="123"
smtp.user="abc@def.com"

Aanchal Sikka

Avatar

Level 2

@aanchal-sikka Restarting the bundle works. But, we'll not have permission in actual envts to do this.

Avatar

Community Advisor

Hi @Divya_T13 

Do you know when does the issue start occurring that is lets say you have started instance and its working fine. Does it start occurring after sometime or what is the event?

 

Thanks,

Nupur

Avatar

Level 2

Hi @Nupur_Jain 

In my case, I have a workflow that includes a custom process step to send email notifications. It works fine after starting or restarting the instance, or after starting and stopping the "Day Communique 5 Mailer" bundle. But, the issue occurs after some time.

Avatar

Community Advisor

Hi @Divya_T13 , The MessageGatewayService's lifecycle is container managed. If the service is fine after restarting the instance but stops working after a while, i will be looking in the bundles that is getting installed that forces a OSGI bundles refresh. Can you try the following debugging steps to confirm it that's true:
1. Make sure the Message Gateway Service is able to send emails.

2. Deploy the custom code on the instance, monitor the logs at this point to look for Service Unregister/Register events specifically the MessageGatewayService.

3. Test the Service to confirm if it broke. If not, repeat with another custom bundle.

 

Though time taking, that is the best shot at getting to the root cause. Good luck!

 

Regards,

Fani

Avatar

Level 2

This issue appears to be related to the MessageGatewayService not properly initializing or retaining the configuration settings in AEM (Adobe Experience Manager). Here are some steps to help troubleshoot and potentially resolve the problem:


1. Verify SMTP Configuration

Ensure the Day CQ Mail Service (com.day.cq.cq-mailer) configuration in the Felix Console (/system/console/configMgr) is set up correctly:

  • Check the SMTP host, port, username, password, and other relevant settings.
  • Test these credentials outside AEM (e.g., via a command-line mail client) to confirm they work.
  • Ensure the "From" address and reply-to addresses are configured and valid.

2. Inspect Bundle States

  • Go to Felix Console > Bundles (/system/console/bundles) and verify the state of the "Day Communique 5 Mailer" bundle.
  • If it's in a resolved or stopped state instead of active, start or restart the bundle.
  • Check for any dependency bundles that might be missing or not active.

3. Analyze Logs

  • Look at the AEM error logs (/crx-quickstart/logs/error.log) for more details about the error or warnings related to the MessageGatewayService.
  • Check for any clues during AEM startup or the email sending process.

4. Cache/Service Refresh

The issue may stem from cached or stale configurations. Restarting the service resolves the problem temporarily because it forces the bundle to reinitialize. Automate or script the refresh to confirm:

  • Clear the OSGi configuration cache:
    rm -rf /crx-quickstart/repository/cache
  • Restart AEM after clearing the cache.

5. Debug Service Dependency

The null values for messageGatewayService.getGateway(HtmlEmail.class) indicate a problem with how the service is being injected or accessed:

  • Ensure the MessageGatewayService is properly referenced in your workflow code using:
    @Reference
    private MessageGatewayService messageGatewayService;
  • Check if HtmlEmail is part of the imported libraries and correctly included in the project's dependencies.

6. Update to Latest AEM Service Pack

AEM 6.5 SP17 is relatively new, but Adobe might release hotfixes for this version. Check if there are any known issues or updates for your AEM instance. If needed, contact Adobe support.


7. Use a Scheduled Health Check

Since restarting the instance or bundle temporarily resolves the issue, you can implement a health check or automated service monitor to detect and resolve failures in real-time. This avoids manual intervention.


8. Test in a Lower Environment

Recreate the issue in a staging or development environment to confirm the behavior and test potential fixes.


If none of these steps resolve the issue, please share more specific logs or details about your environment and custom workflow setup for deeper analysis.