AWS SES + Gmail = Free Business Email ID
Tags: startup, aws, productivity
Published: 2020-09-12 19:50:15

My [website](https://simplq.me/) is hosted on AWS Free Tier, and I wanted to create a free company/business email address for people to contact me. If you are already on AWS, and want to create an email address like contact@simplq.me it doesn't cost anything.

What you need:
1) An AWS Account
2) A domain name (simplq.me in my case)
3) Gmail account (Other email services should also work)

What **you don't need**: A GSuite Account

(If your domain is on Google Domains, [setting up](https://support.google.com/domains/answer/3251241?hl=en#emailForwarding) email forwarding is easy.)

I've covered all the necessary steps in brief, but if you need help or get stuck somewhere, let me know in the comments. 

If you want two way communication, not all regions support it. I set this up in `us-west-2 (Oregon)` even though my website is hosted in `ap-southeast-1 (Singapore)`.

## Setup SES - Simple Email Service

On AWS Console, switch to us-west-2, go to SES, and verify your domain:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/kpwjuhaikyzev6phddvn.png)

If your DNS is managed by Route53, Amazon can automatically update the entries, click on "Use Route53" button on the next page. Otherwise, you have to manually set the entries in your current DNS registrar.  
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/3bdh3xd0kwnnvohf69qb.png)

##Verify Your Current Email

This step is easy, your current Gmail address that you want Amazon to relay all communications to, verify it with SES. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/stv5xvuw8rrbzwb2zh0n.png)

You'll get a confirmation email, as part of the verification process.

## Configure SES Email Forwarder

In the coming steps, we will configure SES to trigger a lambda which will forward emails to our personal email.

Create a blank Node.js 12.x runtime Lambda function with no triggers in the same region, and use [this](https://github.com/arithmetric/aws-lambda-ses-forwarder/blob/master/index.js) file as the function code.

There is a config object in the code which requires some tweaking:

```
var defaultConfig = {
  fromEmail: "contact@simplq.me",
  subjectPrefix: "",
  emailBucket: "<s3-bucket-name>",
  emailKeyPrefix: "mails/",
  allowPlusSign: true,
  forwardMapping: {
    "contact@simplq.me": [
      "<your-gmail-id>@gmail.com"
    ]
  }
};
```

`fromEmail` should be the business email which your customers would see. We will later create an S3 bucket to store our emails. Choose a bucket name and give it as `emailBucket`. In the `forwardMapping` section, you should configure the gmail address which you verified in the previous step.

[arithmetric/aws-lambda-ses-forwarder](https://github.com/arithmetric/aws-lambda-ses-forwarder) is a awesome repo, it supports many more configurations, you should check it out if you want to create and forward multiple emails, or forward emails to multiple people.

Attach this policy to the service role of the Lambda, to give it access to the S3 bucket, and also SES:

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:GetObject"
            ],
            "Resource": "arn:aws:s3:::<s3-bucket-name>/*"
        },
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": "ses:SendRawEmail",
            "Resource": "*"
        }
    ]
}
```

## Create a Rule in SES

This ties everything together, go back to SES console and create a new Email Receiving -> Rule Set. You will set a rule, where you configure two "Actions", one to save all emails to a S3 bucket which you can create from this screen, and another to trigger the Lambda created in the previous setup to forward the mails. Use the below screenshot as reference:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/aqpv5jegsmdcdclbtvs8.png)

At this point, if you send an email to your business email, the personal Email ID should receive it. Test and make sure that it works, use Cloudwatch Logs for the lambda to debug in case of issues.

## Configure Gmail

Next is to add this new email as a new identity to your Gmail account. Go to SES's SMTP Settings and create a new SMTP Credential.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/y2ay5hu223cwh38e69ul.png)

At the end, you'll get a username and a password, which you should add to your Gmail Settings:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/rfdhv4zxe4n297hb0lwy.png)

## Last Step - Verification

Initially your newly configured Amazon SES service will be quarantined (sandboxed) by Amazon as a measure of protection against possible abuse and spam. To remove it from quarantine and allow normal mailing, as the last step, you need to open a support ticket to Amazon and fullfill a request. Otherwise you will see how the emails you send bounce with the following error message:
```
554 Message rejected: Email address is not verified. The following identities failed the check in region ...
```

They approved within minutes in my case. Go to Sending Statistics section to raise a request:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qwyly6jzunv8xmryoa00.png)

That's it! Your business email is ready to use. Let me know in the comments section if you face any issues. Hope you enjoyed it. 

--

If you want to reach out to me for consulting or mentoring, you can book a slot [here](https://www.hiretheauthor.com/daltonfury42).