Is there a way to check if a SES email sent was delivered successfully or bounced using javascript sdk

Viewed 1499

I am sending emails in JavaScript using the AWS SES SDK. I will have users calling this function and they need to know whether their emails were delivered successfully or not. This is my current code:

var aws = require("aws-sdk");
let credentials = aws.config.credentials;
aws.config.update({
    region: "us-east-1",
});

// Specify a configuration set. 
const configuration_set = "test";

const ses = new aws.SES();

var to = ['bounce@simulator.amazonses.com']
var from = 'tester@gmail.com'

const params = {
    Source: from,
    Destination: { ToAddresses: to },
    Message: {
        Subject: {
            Data: "Sending emails through SES"
        },
        Body: {
            Text: {
                Data: 'Hello world www.google.ca',
            }
        }
    },
    ConfigurationSetName: configuration_set
};


ses.sendEmail(params, function (err, data) {
    if (err) throw err
    console.log(data)
    //Do something here to check if email was delivered successfully
})

The data returned in the console is a RequestId and a MessageId. I have done research on if its possible to check the delivery status of an email using the MessageId but it does not seem like it is. Is there any other way I could let whoever calls this function know whether or not their email was delivered successfully or bounced/did not make it.

1 Answers

The message id generated from this code only tells you that SES has accepted the email and it will try to deliver it to the destination. The same message Id will be inserted as a header when ses delivers it to the recipient, this doesn’t tell you whether it has delivered or not, you would need to enable notifications on ses for delivery, complaint, bounce on the verified identity. SES provides an option to notify it both ways, to a sns subscriber or to the return path address.

https://docs.aws.amazon.com/ses/latest/DeveloperGuide/monitor-sending-activity-using-notifications.html

Related