DEV Community

Cover image for How to receive emails in a S3 bucket with AWS SES?
juanc4milo
juanc4milo

Posted on • Edited on • Originally published at juanc4milo.dev

How to receive emails in a S3 bucket with AWS SES?

If you want to receive your emails in an S3 bucket, this is the tutorial you should follow.

Prerequisite: Configure an AWS S3 Bucket

You must create an S3 bucket where the emails are going to deposit.

To do this, create a standard bucket type and assign a policy that Amazon SES can write the files to it. The policy must be like the following:



{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowSESPuts",
            "Effect": "Allow",
            "Principal": {
                "Service": "ses.amazonaws.com"
            },
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::bucket-name/*",
            "Condition": {
                "StringEquals": {
                    "aws:Referer": "your-account-ID"
                }
            }
        }
    ]
}



Enter fullscreen mode Exit fullscreen mode

Configuration in Amazon SES

Verify a domain

Enter the domain that the email account belongs to so that Amazon can verify that the domain is yours. To do this, enter the Domains section and enter the domain:

image.png

On the DNS settings you own (Godaddy, Hostgator, Route53, etc.), you must create and enter the verification record sets that Amazon delivers.

image.png

image.png

Amazon must verify the domain, so you must enter this information in DNS settings.

If you are using Cloudfare or any CDN, you must enter these settings too.

Just wait 5 minutes to propagate the changes around the DNSs...

image.png

Set Up an MX record in your DNS Settings

A mail exchange record (MX record) is a setting that specifies the mail servers that can accept email sent to your domain.

To add an MX record to your domain's DNS settings, you must do the following:

  • Log in to the DNS provider management console.
  • Create a new MX record.
  • In the Name field of the MX record, specify the domain followed by a period. Example: mydomain.com.
  • For Type, select MX.
  • In Value, enter the following:


inbound-smtp.regionInboundUrl.amazonaws.com


Enter fullscreen mode Exit fullscreen mode

For example, if you are using the US East (N. Virginia) region, replace the region with us-east-1. It should be:



inbound-smtp.us-east-1.amazonaws.com

Enter fullscreen mode Exit fullscreen mode




Create a Receive Rule Set

To create a set of rules in Amazon SES, go to the Rule Sets section and click on the Create a Rule Set button:

image.png

Specify the email account or domain from where you want to receive emails. If none is specified, you will receive emails from all accounts:

image.png

Select an action, of type S3:

image.png

In the action configuration, select the name of the bucket, and say the prefix to save the files (path in S3):

image.png

Specify a rule name, enable it and check "Enable spam and virus scanning" if you want AWS to scan the emails:

image.png

Review your configuration:

image.png

When you hit the save button, the Rule set is created and AWS sends a notification file to the prefix bucket.

image.png

You can download it and add a .EML extension to open with Outlook or any email application and read the AWS setup notification.

image.png

Test

Login into your preferred mailbox account and send an email to the recipient that you specified in the Rule Set condition:

image.png

After you send the email, check the S3 and you should receive an email file. You can download it and add the extension .EML to open it.

image.png

Finally...

At this point, you can integrate your Cloud Applications with AWS S3 to process your emails.

Other articles that you might like...

Do you like it? You can buy me a beer if you want.

Originally published at juanc4milo.dev

Top comments (0)