Dongfeng Gu

Setup serverless email using SES S3 & Lambda with you personal domain

- 3 mins

What for?

Let’s assume you have a personal domain (mydomain.com). You want to create an email address with you personal domain on it, for example contact@mydomain.com, and forward all the email that send to contact@mydomain.com to your personal email address (personal@outlook.com). This tutorial suits you best.

Setup the domains in SES management console

  1. Verify your domain according to the link.
  2. Set up a receipt rule according to the link.

    Take a note of the Bucket Name in section 5 for later usage.

  3. Login SES console.
    • Choose Email addresses on the left panel.
    • Select Verify a New Email Address.
    • Type in the email address that you want to forward to (in my case is gudongfeng@outlook.com).
    • Go through all the steps and verify your email.

Set the Lambda action for SES

    ...
    fromEmail: "contact@gdf.name",
    
    subjectPrefix: "",
    emailBucket: "contact-email",
    //emailKeyPrefix: "emailsPrefix/",
    emailKeyPrefix: "",
    forwardMapping: {
      "contact@gdf.name": [
        "gudongfeng@outlook.com"
      ]
    }
    ...
    
    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "logs:CreateLogGroup",
                    "logs:CreateLogStream",
                    "logs:PutLogEvents"
                ],
                "Resource": "arn:aws:logs:*:*:*"
            },
            {
                "Effect": "Allow",
                "Action": "ses:SendRawEmail",
                "Resource": "*"
            },
            {
                "Effect": "Allow",
                "Action": [
                    "s3:GetObject",
                    "s3:PutObject"
                ],
                "Resource": "arn:aws:s3:::<your-s3-bucket-name>/*"
            }
        ]
    }
    

S3 bucket policy settings

Login S3 and choose the bucket you just created.

    {
        "Version": "2012-10-17",
        "Statement": [
          {
              "Sid": "AllowSESPuts-<sid-number>",
              "Effect": "Allow",
              "Principal": {
                "Service": "ses.amazonaws.com"
              },
              "Action": "s3:PutObject",
              "Resource": "arn:aws:s3:::<your-s3-bucket-name>/*",
              "Condition": {
                "StringEquals": {
                    "aws:Referer": "<your-aws-account-id>"
                }
              }
          }
        ]
    }
    
comments powered by Disqus
rss facebook twitter github youtube mail spotify instagram linkedin google pinterest medium vimeo