How to send an email with AWS SES and track events with Configuration Sets?
Tags: aws, email, ses, cloud
Published: 2020-11-06 15:21:50

Amazon Simple Email Service is a flexible and scalable email service that allows you to send mail from within any application. 

Through this service, you can send emails and receive information on events that the recipient performs, such as mail delivered to the server, mail opening, or the recipient clicked on any link within the email.

To achieve that, you need to do the following steps:

## Verify a Domain

The first thing you need to do is 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)

Then, 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 this 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)

## Verify Email address

Additionally, Amazon must verify a valid and existing email account. To do this, you must enter Amazon SES to the Email Address section, enter the email account and then go to the inbox of the specified mailbox and click on the link that allows you to verify the account.


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

## Create a Configuration Set

To create a set of configurations in Amazon SES, go to the Configuration Sets section and click on the Create Configuration Set button.


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

Assign a name to the Configuration Set:


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

After assigning the name, it appears with no destinations created:


![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1604525730392/_Kubvcr-E.png)

Enter into the configuration set:


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

You select the way you want to report the events:


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

For this example, I enabled Amazon SNS:


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

AWS SES reported these types of events when they occur. Select the one that suits you best.:

• **Send:** A successful Amazon API call has been made to send mail and Amazon SES will attempt to deliver the mail.

• **Reject:** Amazon SES accepted the email but determined that it contained malware and rejected it, thus, the email will not be sent.

• **Delivery:** Amazon SES delivered the mail to the recipient's mail server.

• **Bounce:** The recipient's mail server has rejected the mail, due to many causes, such as the inbox is full or the recipient does not exist.

• **Complaint:** The email has been delivered to the recipient, but marks it as spam.

• **Click:** The recipient clicked on one or more links included in the email.

• **Open:** The recipient received the message and opened it in their email client.

• **Rendering Failure:** The mail has not been sent due to a problem with the reading of the designated template for the mail.

• **Rendering Success:** The email was sent using the templates configured in Amazon SES.



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

Select the SNS topic before configured to subscribe to notifications:


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

Save the configuration and a box will display the information entered:


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

## Test

To send a test email, select the domain, and click on the Send a Test Email button:


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

Then, enter the following fields, where the RAW field indicated the mail format:


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

Include the following text in the body of the message. This text includes a tag that indicates the <configuration set> that AWS used to report the events:


```
X-SES-CONFIGURATION-SET: myConfigSetsName
X-SES-MESSAGE-TAGS: DimensionName=DefaultValue
From: emailfrom@domainexample.com
To: emailto@domainexample.com
Subject: Test email
Content-Type: multipart/alternative;
    boundary="----=_boundary"

------=_boundary
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

This is a test email with config sets.

<a href="https://aws.amazon.com/">Amazon Web Services</a>
------=_boundary
``` 


Click on the send button and an email should reach the recipient's inbox:


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

## One last thing...

To report an open email, Amazon SES includes a blank image at the end of the email so that when the user opens the email, it triggers an event that AWS captured.

For this reason, a restriction of the service is that the originating email account must be marked as a safe sender so when the recipient opens the email, it downloads all its content completely and could launch the event.

### 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)

**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)_