How to receive emails in a S3 bucket with AWS SES?
Tags: aws, ses, cloud, email
Published: 2020-11-07 20:52:16

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:

 
```json
{
    "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"
                }
            }
        }
    ]
}

``` 


## 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](https://cdn.hashnode.com/res/hashnode/image/upload/v1604518525966/cWSnzr7ww.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](https://cdn.hashnode.com/res/hashnode/image/upload/v1604518890563/YBjGDDb0f.png) 

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1604519317424/-8HYWbL8V.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](https://cdn.hashnode.com/res/hashnode/image/upload/v1604519522061/ZaBh-DAcX.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
``` 


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
``` 


### 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](https://cdn.hashnode.com/res/hashnode/image/upload/v1604636078121/oyTBJiMjt.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](https://cdn.hashnode.com/res/hashnode/image/upload/v1604636096531/C_PvDMSFj.png)

Select an action, of type S3:


![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1604636113335/enOBqh1D4.png)

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


![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1604636134859/8_Y_uQaA_.png)

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

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1604636588954/HQblYP88-.png)

Review your configuration:


![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1604636756670/e5R6Jhiht.png)

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


![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1604636822621/Bkm-eS3h0.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](https://cdn.hashnode.com/res/hashnode/image/upload/v1604636954982/J8nbMWTVV.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](https://cdn.hashnode.com/res/hashnode/image/upload/v1604637067677/rRwj7Mb3l.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](https://cdn.hashnode.com/res/hashnode/image/upload/v1604637133327/C9GFcvOeX.png)


## Finally...

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

### Other articles that you might like...

* [Redis - Instalación y Configuración](https://juanc4milo.dev/redis-instalacion-y-configuracion)
* [AWS S3 Batch Operations](https://juanc4milo.dev/aws-s3-batch-operations)
* [AWS S3 Inventory](https://juanc4milo.dev/inventario-aws-s3)
* [Qué ofrece y cómo se configura AWS Elasticache?](https://juanc4milo.dev/aws-elasticache)
* [Qué ofrece y cómo se configura Elasticache en AWS?](https://juanc4milo.dev/aws-elasticache)
*  [How to use Redis with Spring in Java](https://juanc4milo.dev/redis-with-spring-in-java)
* [How to send an email with AWS SES and track events with Configuration Sets?](https://juanc4milo.dev/send-email-with-aws-and-track-events)

**Do you like it?** You can [buy me a beer](https://buymeacoffee.com/juanc4milo) if you want.

> _Originally published at [juanc4milo.dev](https://juanc4milo.dev)_