Email Forwarding with Amazon SES

I’m using AWS for the domain and web site of my high school alumni association. Hosting a static site on S3 is practically free, so we just end up paying for Route 53.

All that was missing was the ability to set up a few incoming email addresses to forward to external addresses. It turns out that Simple Email Service (SES) doesn’t offer simple email forwarding. There’s an AWS blog here that provided the beginning of what I needed: you set up SES to accept email, write messages to S3, and trigger a Lambda function to send a new email with the original email attached.

The primary limitations of this solution are:

  1. It assumes you want to forward all of your incoming email to a single destination address (or that you’re willing to set up a Lambda function per destination). I’d like the flexibility to set up several forwarders in a single Lambda.
  2. It assumes you want the original email to be attached as an .eml file. Since you can’t open an .eml file in web clients like gmail, that didn’t work for me.

I made the improvements I needed and published the Lambda code here: https://github.com/karlkranich/lambda-ses-email-forwarder. If you want to implement it, you’ll need to follow most of the instructions in the AWS blog to set up SES, S3, and Lambda. Then just skip the MailRecipient environment variable and instead create a MailAddressMap environment variable that contains a string formatted like this:

'[{"from":"fromaddress@example.com","to":"newaddress@gmail.com"},{"from":"fromaddress2@example.com","to":"newaddress2@anotherdomain.com"}]'

If you have any trouble getting it working, you should be able to find troubleshooting information in CloudWatch logs.

Leave a Reply

Your email address will not be published. Required fields are marked *