1
votes

I have an AWS Lambda function:

sendEmail.js

const AWS = require('aws-sdk');
const ses = new AWS.SES();
 
function sendEmail(subject, message, senderEmail) {
  const params = {
    Destination: {
        ToAddresses: [
            process.env.VERIFIED_EMAIL
        ]
      },
    Message: {
        Body: {
            Text: {
                Data: message,
                Charset: 'UTF-8'
            }
        },
        Subject: {
            Data: subject,
            Charset: 'UTF-8'
        }
    },
    Source: process.env.VERIFIED_EMAIL,
    ReplyToAddresses: [senderEmail]
  }
  return ses.sendEmail(params).promise();
}
 
module.exports = sendEmail;

Called from

index.js

const sendEmail = require('./sendEmail');
exports.handler = async (event, context) => {
    return sendEmail(event.subject, event.message, event.email).then((response) => { context.done(null, 'Email sent')});
   
};

I have the env. variable VERIFIED_EMAIL set to a personal e-mail that is verified by AWS/SES.

My test case:

{
  "email": "[email protected]",
  "subject": "desc",
  "message": "Hello!"
}

Which passes and returns "Email sent" but I don't actually receive an e-mail. I've also deployed the API-GATEWAY and I can call the API w/ Postman and I receive the same "Email sent" message but no e-mail is actually sent.

I don't think it should be an issue with being in sandbox mode because the email I am sending it from is verified.

PS:

When Looking at the SES management console it says that the emails are being sent (they take up part of the 200 daily quota) and then that none of them were bounced or rejected but simply deliveries.

1
I believe the issue is with Outlook, as I added a personal Gmail account and everything worked as expected. - Kippet

1 Answers

1
votes

A few things you should check with your SES before diving deeper.

  1. In sandbox mode both "source email address" and "destination email address" have to be verified. Instead a mail won't be delivered.

  2. In case you verify Email Domain so appropriate dns and DKIM records have to be added in your domain. Plus additional whitelist clearance is assumed if you use corporate domains.

  3. Your IAM AWS user should be permitted to execute SES api calls. Check your policies and roles. Check Secret Key and Secret Id you use.

  4. There might be problems when you use inappropriate email types and email sending endpoints (eg you try to send "SingleTemplatedMessage" via "BulkTemplatedMessage" endpoint)

Check all this things first.

Then you might try something else. In my project we use AWS SDK based on java to interact between BE and SES. It provides logs containing message statuses (if a message was sent successfully, rejected, its id and other errors if they occurred)

Additionally to keep track on every single message you send you can set up SES-SNS to exchange with notifications. It's described in the following article

https://sysgears.com/articles/how-to-track-email-status-with-amazon-ses-and-amazon-sns/

Other problems might occur in your mail client (spam filters etc)