Receive Emails Using Amazon SES : A Step-by-Step Guide

Omar faruk zihad - Aug 15 - - Dev Community

You might already know that Simple Email Service (SES) of Amazon Web Services (AWS) is great for sending emails, but did you know it's just as powerful for receiving them? Whether you want to store emails for later processing, automatically trigger actions when an email arrives, or even forward emails to another address, AWS SES has you covered. In this blog, I'll show you how to set up AWS SES for receiving emails in a way that's secure, reliable, and tailored to your needs. Let's dive in!

Understanding the Basics

Receiving emails with AWS SES involves several components:

  • SES Receiving Rules: These rules determine how incoming emails are handled.

  • Amazon S3: A storage service where you can store incoming emails.

  • AWS Policies: A policy is an object in AWS that, when associated with an identity or resource, defines its permissions.

Setting Up SES for Receiving Emails

  • Configure identities for Receiving Emails
    Before you can start receiving emails, you need to configure identities. In Amazon SES (Simple Email Service), an identity refers to a domain or email address that you use to send or receive emails through SES. Before you can send an email, SES needs to verify that you own the identity, ensuring that emails sent from that identity are legitimate and authorized.

    • Navigate to the AWS Management Console and open the SES service.
    • In the SES console, go to the Configuration > Identities > Create identity.

Identity Creation Page

  • Here we will use the domain as the receiver. Fill up the domain name. You can skip rest of the options.
  • After creating you will be taken to the details page. Scroll down to the DNS records and add the required DNS records to your domain's DNS settings.

DNS records

This process may take a few minutes. Once the domain is verified, you can use it to receive emails.

  • Create a Receipt Rule Set
    A receipt rule set determines how SES handles incoming emails for your verified domain:

    • In the SES console, navigate to Configuration > Email receiving and click "Create a Rule Set" and name it appropriately.
    • Navigate to the details of the rule set and click "Create Rule."

Create rule page

  • Define conditions such as the recipient's email address or domain. Here if somebody sends mail to mail@abc.com then this rule will be applicable.

Recipient condition

  • Next you have to create actions which will execute on receiving the email. You can specify multiple actions under each rule.

Actions

As you can see there are many actions available to use. Let's know about them to see which fits your purpose

  • S3 Action: By default there are no mechanism to see the received email. By storing it in Amazon S3 bucket, we can later view and reuse the email .

  • Lambda Action: Trigger an AWS Lambda function to process the email.

  • SNS Action: Send a notification via Amazon SNS.

  • Bounce or Reject: If necessary, you can also bounce or reject emails.

After configuring the actions, save the rule. Activate the rule set to apply it to incoming emails.

Storing Emails in Amazon S3

Storing incoming emails in S3 is one of the most common use cases:

  • Set Up an S3 Bucket:
    • Create a new S3 bucket or choose an existing one where the emails will be stored.
    • Ensure the bucket has the correct permissions to allow SES to write emails to it by modifying the policy of the bucket using below policy
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowSESPuts",
            "Effect": "Allow",
            "Principal": {
                "Service": "ses.amazonaws.com"
            },
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::<your-bucket>/*",
            "Condition": {
                "StringEquals": {
                    "AWS:SourceArn": "arn:aws:ses:<your-region>:<your-account-id>:receipt-rule-set/<you-rule-set>:receipt-rule/<your-rule-name>",
                    "AWS:SourceAccount": "<your-accound-id>"
                }
            }
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode
  • Configure the S3 Action in SES:
    • In your receipt rule, choose the "S3" action.Specify the bucket name, object key prefix (if any), and whether to include the email headers.

Bucket selection

Send a test email to your domain and verify that it appears in the specified S3 bucket.You should see an email object in the s3 bucket.

Conclusion

AWS SES provides a flexible and scalable solution for receiving emails, integrating smoothly with other AWS services like S3, Lambda, and SNS. Whether you're storing emails, automating responses, or triggering notifications, SES can be tailored to fit your specific use case. With the steps outlined in this guide, you can set up a robust email-receiving system that meets your needs and scales with your business.

. . .
Terabox Video Player