Skip to content

SES how to send emails from a verified domain to emails belong to that same said domain?

0

I have a verified domain in AWS SES say 'my-custom-domain.com'. And I also created a personal email address belong to this domain, hosted at an external mail server. I have set up SES to receive every incoming email sent to this domain. And I've set up the receiving rules to store incoming emails in S3, and a Lambda function to listen to putObject event emitted by S3. The Lambda function will get the emails stored in S3 and forward them to the aforementioned email address.

Now is the interesting part. Whenever I send a new email from Gmail to the personal email address. The new email is caught and stored in S3 as expected. The Lambda function is triggered on putObject event. It will retrieve the email stored in S3 and send it to the personal email address, but the email sent from the Lambda function ended up in S3 again and the Lambda function is triggered again, but this time on the newly-stored email. This is a recursive loop.

How can I make the email actually sent to personal email address?

1 Answer
0

Modify your Lambda function to differentiate between emails received directly (from external senders like Gmail) and emails sent by the Lambda function itself. You can achieve this by:

Adding a Custom Header

Before forwarding the email in Lambda, append a custom header (e.g., X-Lambda-Forwarded: true).

Filtering Incoming Emails

Modify your Lambda function to check for this header.

If the header exists, skip storing the email in S3 to prevent it from triggering the function again.

answered a year ago

EXPERT

reviewed a year ago

  • Your solution doesn't work. Since the personal email lives in the custom domain, all incoming email will be sent to this domain, hence captured by SES. In my settings, the Lambda function is at the tail end of the email-processing pipeline. So it goes like this: sender -> SES -> save the email to S3 -> S3 trigger a putObject event -> the Lambda function is invoked on putObject event, put the filter header in the email and forward to personal email address -> the email doesn't go to the receiver but comes back to SES again because of the aforementioned traffic rule, so the email ends up in S3 again. I'm thinking my solution for this problem might be using an SMTP relay.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.