Expand my Community achievements bar.

Is there a way to get response code for messageGateway.send(email) method

Avatar

Level 2

I am facing an issue where I am using AEM messageGateway service to send the email. In case where emails are not triggered successfully, I am not getting any error message and it always ends with success message. Is there a way to check if the email was sent successfully or not ?  Any help would be highly appreciated.

Below is the example of code:

try {

final MessageGateway<Email> messageGateway = messageGatewayService.getGateway(Email.class);

//all details of the mail in between to be added to email object

messageGateway.send(email);
} catch (Exception e) {
LOGGER.error("Error occurred in sendEmail {}", e);
}

 

3 Replies

Avatar

Employee Advisor

EMails are sent via email gateways, and sending emails is highly async. That means that as soon as this email is successfully submitted to the email gateway, this method will return. What happens afterwards it out of scope of this method. That means if the email is dropped or rejected because some AI considers it as spam, your code will never know.

Avatar

Level 2

Thank you for the response! Is there any alternate way to send emails where we get response message as well ?

Avatar

Employee Advisor

No that easy. Email is a bit different from the Web...

 

First it's all async. And then you would need to have a mailbox, which can receive emails. You would need to poll this mailbox and see if a response arrived (with a non-trivial question being how you detect a response to a certain email). And so on.

 

Can you describe your usecase? Maybe there's a different way to achieve the same.