Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Getting exception while sending mail using Day CQ Mail Service in cloud

Avatar

Level 4

Helllo All,

 

There is custom worklfow process step to send mail using Day CQ Mail Service configs. This is working fine in local AEM sdk setup. But we I deployed these changes to Cloud instance I am getting below error:
com.adobe.granite.workflow.core.job.JobHandler Error executing workflow step
com.adobe.granite.workflow.WorkflowException: Process execution resulted in an error
at com.adobe.granite.workflow.core.job.HandlerBase.executeProcess(HandlerBase.java:204) [com.adobe.granite.workflow.core:2.1.104]
at com.adobe.granite.workflow.core.job.JobHandler.process(JobHandler.java:300) [com.adobe.granite.workflow.core:2.1.104]
at org.apache.sling.event.impl.jobs.JobConsumerManager$JobConsumerWrapper.process(JobConsumerManager.java:502) [org.apache.sling.event:4.3.8]
at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.startJob(JobQueueImpl.java:351) [org.apache.sling.event:4.3.8]
at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.access$100(JobQueueImpl.java:60) [org.apache.sling.event:4.3.8]
at org.apache.sling.event.impl.jobs.queues.JobQueueImpl$1.run(JobQueueImpl.java:287) [org.apache.sling.event:4.3.8]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: com.day.cq.mailer.MailingException: Invalid mail service configuration.
at com.day.cq.mailer.impl.DefaultMailService.send(DefaultMailService.java:292) [com.day.cq.cq-mailer:5.4.22]
at com.day.cq.mailer.impl.DefaultMailService.send(DefaultMailService.java:46) [com.day.cq.cq-mailer:5.4.22]
at com.hostplus.program.core.services.NotificationMailService.execute(NotificationMailService.java:125) [hostplus-program.core:1.0.0.SNAPSHOT]
at com.adobe.granite.workflow.core.job.HandlerBase.executeProcess(HandlerBase.java:198) [com.adobe.granite.workflow.core:2.1.104]

There is one solution to restart com.day.cq.cq-mailer bundle but we dont have access to system console on cloud instance. Anyone is

11 Replies

Avatar

Community Advisor

Hello @supriya-hande 

 

Can you please confirm if you have followed all the steps as described on https://experienceleague.adobe.com/docs/experience-manager-learn/cloud-service/networking/examples/e...

  • Connections to mail services from AEM as a Cloud Service must be proxied out.
  • Ensure the the appropriate advanced networking configuration has been set up 

  • OSGi configuration using proxy


Aanchal Sikka

Avatar

Level 4

Hi @aanchal-sikka

Thanks for your reply. I followed above link and setup Env variable in cloud manager. I have created OSGI config and provided env values as below:

{
"smtp.host" : "$[env:AEM_PROXY_HOST;default=proxy.tunnel]",
"smtp.port": 30587,
"smtp.user": "$[env:EMAIL_USERNAME]",
"smtp.password" : "$[secret:EMAIL_PASSWORD]",
"smtp.ssl": false,
"smtp.starttls" : true
}
 
But now am getting exception while reading smtp.user value in java:
org.apache.commons.mail.EmailException: javax.mail.internet.AddressException: Local address contains illegal character in string ``$[env:EMAIL_USERNAME]''
I am not getting why this is happening or 
It seems to be using that $[env:… as a string instead of substituting it for the value

Avatar

Community Advisor

Hello @supriya-hande 

 

Are you getting these errors on local or server?

 

  • On local you would have to use the original settings, what you might have configured.The env variables should work on server.
  • Have you set the variables via cloud manager, for that specific environment, where you are testing? After setting env variables, wait for some time. It takes some time to take effect. I guess you would see some message regarding pods restarting in CM. Don't remember clearly now.

Aanchal Sikka

Avatar

Level 4

Hi @aanchal-sikka 

 

  • I am getting these error in Cloud server not in local AEM.
  • I have set the variables yesterday via cloud manager, for that specific dev environment and I was validating this today morning. Then I found this issue in logs. I think its not reading cloud variables properly in java code.

    conf = configAdmin.getConfiguration(pid);

    Dictionary<String, Object> props = conf.getProperties();

    String smtpUser = (String)props.get("smtp.user");

    Its reading values of smtp.user as 
    $[env:EMAIL_USERNAME] and not actual value set in cloud

Avatar

Community Advisor

@supriya-hande 

I guess you are using custom code for sending emails.

Can you possibly share snippet of your code?

 

Meanwhile, to check that your Proxy set-up and configs are correct, try sharing link of an Asset to you email ID:

- Select an asset

- Click Share Link

- Add details

- Check if you receive email


Aanchal Sikka

Avatar

Level 4

Hi @aanchal-sikka 

Yes I have created custom workflow process step to send email notification for approval when user starts workflow. Below is the snippet:

@Component(service = WorkflowProcess.class, property = { "process.label=Notification Email" })
public class NotificationMailService implements WorkflowProcess {

@Reference
private MessageGatewayService messageGatewayService;
 
@Reference
private ConfigurationAdmin configAdmin;
 
private final Logger LOGGER = LoggerFactory.getLogger(getClass());
protected final String pid = "com.day.cq.mailer.DefaultMailService";
 
public void execute(WorkItem item, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException {

ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver.class);
Externalizer externalizer = resourceResolver.adaptTo(Externalizer.class);
String path = item.getWorkflowData().getPayload().toString();
String comment = StringUtils.EMPTY;
String userId = StringUtils.EMPTY;

String owner = item.getWorkflow().getInitiator();
LOGGER.info("owner+++++++++++++++++++++++++++++++++++++++++++ " + owner);

Date startdate = item.getTimeStarted();
String date = startdate.toString();

LOGGER.info("startdate+++++++++++++++++++++++++++++++++++++++++++ " + date);
 
String finalURL = externalizer.authorLink(resourceResolver, path) + ".html";
LOGGER.info("finalURL+++++++++++++++++++++++++++++++++++++++++++ " + finalURL);
 
String inboxURL = externalizer.authorLink(resourceResolver, "/aem/inbox") + ".html";

try {
Configuration conf = null;
conf = configAdmin.getConfiguration(pid);
Dictionary<String, Object> props = conf.getProperties();
String smtpUser = (String)props.get("smtp.user");
// Declare a MessageGateway service
MessageGateway<Email> messageGateway;

// Set up the Email message
HtmlEmail email = new HtmlEmail();
// Set the mail values
String[] emailToRecipients = getRecipientsId(resourceResolver);

String salutation = "<b>Dear Content Approver" + ",</b><br>";
 
String message = "<b><p>The " + owner + " has submitted content for your approval. "
+ "Please review at your earliest convenience. <br>";
 
String approveLink = "After you review the content, click the Approve/Reject link here <a href=" + inboxURL +">Approve/Reject</a>";

String data = "<p><b>Page Path:</b>\t" + finalURL
+ "</br>" + "<b>Owner:\t" + owner + "</br>" + "<b>Initiated:</b>\t" + date + "</p>";

email.addTo(emailToRecipients);
email.setSubject("Please review and take action ");
email.setFrom(smtpUser);
email.setMsg(salutation + message + data + approveLink + comments);
// Inject a MessageGateway Service and send the message
messageGateway = messageGatewayService.getGateway(HtmlEmail.class);

// Check the logs to see that messageGateway is not null
messageGateway.send((Email) email);

} catch (EmailException e) {
LOGGER.error("Error while sending mail", e);
} e);
 
Below is the OSGI config:
{
"smtp.host" : "$[env:AEM_PROXY_HOST;default=proxy.tunnel]",
"smtp.port": 30587,
"smtp.user": "$[env:EMAIL_USERNAME]",
"smtp.password" : "$[secret:EMAIL_PASSWORD]",
"smtp.ssl": false,
"smtp.starttls" : true
}

Avatar

Level 4

@aanchal-sikka Did you see above code snippet I put? I am not sure if am missing something while reading smtp.user as environment variable from cloud.

Avatar

Community Advisor

@supriya-hande 

 

Will check the code..

Meanwhile, were you able validate the proxy set up by triggered email via "Share Link" on asset?


Aanchal Sikka

Avatar

Level 4

Hi @aanchal-sikka 

Yes I tried sharing assets as mentioned but Share Link is not correct one. I have deployed mail send functionality code on one of the test instance and there I am trying to share asset link but I see that share link is showing dev instance URL not test instance and I think thats why am getting error: Email service not available, cannot send asset share email.
Email service code is only available on test instance.

Avatar

Community Advisor

Hello @supriya-hande,

 

Adding with @aanchal-sikka, can you check the following

- access to the server using SSH

- then try to connect to the smtp server using telnet on the expected port  

telnet smtp.example.com 25

- If you can not connect, you might need to explicitly open the port(s) for any IP (outbound request) on the load balancer. You can raise support ticket for that

 

Thanks

Avatar

Administrator

@supriya-hande Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni