2021 Fillmore Street #1128

}

24/7 solutions

Share
aws logo partner

AWS SES

Adding emails to an automated workflow for automated processing can be a difficult task. To connect to mail servers and poll for new emails, apps have traditionally used the POP protocol. Once the emails arrive, the application processes them inline and takes action. POP is an inefficient and error-prone approach, this can lead to workflows missing messages. There are drawbacks to using this strategy because it requires polling and adds inefficiencies in design.

Introduction

A Cost-effective, scalable, and customizable email service, Amazon Simple Email Service (Amazon SES) can execute spam checks and virus scans, among other things. Learn how to utilize Amazon SES to automate the processing of emails in real time and interface with an application.

In this article, we’ll look at how to automate customer relationship management (CRM) platforms and how to process emails relating to customer contact or direct email requests (also known as order processing). One use case for this is copying a customer engagement email to Salesforce (or any other database), where it is stored and can later be classified or related to the relevant client account or opportunity. When developing an application that needs to receive emails from a mailbox, a developer would usually have to utilize a mail library (such as JavaMail if the application is written in Java) to make a call to the mailbox, authenticate, and then pull the messages into an object in the application. Essentially, this would entail polling the mailbox every 10 – 15 minutes to check for new messages, handling problems when the mailbox is unavailable, and ensuring that the mailbox is always fully operational. This solution can assist you in implementing automated processing of emails as they arrive in a mailbox without the need to poll the mailbox for new messages. The serverless architecture can be used to implement the entire solution.

Solution

 

With the help of SES, you may automate the processing of emails within an application workflow. The option in SES to save received emails in S3 and activate a Lambda function to process the message will be used to avoid polling a mailbox for the message. Using email, this sample application demo receives simple orders, which are then processed automatically and the information are kept in DynamoDB. The high-level architecture is depicted in the diagram below:

Emails are received by Amazon SES and delivered to an Amazon S3 bucket by a serverless application. Amazon Comprehend is used to detect the prevailing language in the message body of the application. It then searches Amazon DynamoDB for the email address of a support organization that specializes in that subject. The final step is to send the email to the intended recipient via Amazon SES. Incoming emails can be processed or audited further by archiving them on Amazon S3.

An event begins when a consumer sends an email to a generic support address, such as [email protected], indicating that they need assistance. A recipient rule in Amazon SES makes it possible for the service to hear this email. Messages are written to an Amazon S3 bucket with a certain prefix according to the rule.

On object creation events, this bucket and prefix are configured using S3 Events, which triggers a Lambda function in this bucket. After reading the email, parsing its contents, and sending them to Amazon Comprehend for language detection, the Lambda function returns a result. Amazon DynamoDB looks up the detected language code in an Amazon DynamoDB table that contains mappings between language codes and support group email addresses for the languages in which they are detected. One support group may respond to emails in English, while another support group could respond to emails in French. It is the responsibility of the Lambda function to determine and deliver the same email address to several recipients via a resend operation (email forwarding). Assume that the lookup does not produce any results for the destination address, or that the language could not be determined. Alternatively, the email is forwarded to a catch-all email address that was set during the application’s deployment.

Free AWS Services Template

Download list of all AWS Services PDF

Download our free PDF list of all AWS services. In this list, you will get all of the AWS services in a PDF file that contains  descriptions and links on how to get started.

Prerequisites

To utilize Amazon SES to receive email messages, you must first verify that you control the domain that will be used. Consult the manual for instructions on how to validate your domain using the Amazon SES console. Amazon Route 53 will help you to register a domain name if you don’t already have one registered.

Step 1: Create an S3 Bucket for email storage on Amazon Web Services.

Begin by creating an S3 bucket in which all incoming emails will be kept in order for the lambda to be able to process the entire email in its entirety. A policy must be associated to the bucket in order for SES to be able to place objects in the bucket.

The following modifications should be made to the preceding policy illustration:

  • If you wish to write to an Amazon S3 bucket, substitute the name of the bucket for myBucket.
  • Use your AWS account ID instead of 111122223333.

Step 2:  To create a DynamoDB table in order to simulate an application.

Next, create a DynamoDB table using the following parameters: Information about incoming orders is saved in a DynamoDB table. For the purposes of this example, we will use an email address as the partition key for a table. As an example of a data model, consider the following:

Step 3: Create a Lambda Function that is activated by SES and is used to process email messages.

To proceed, write the Lambda function to process the email and transmit data into the DynamoDB table, which you can see in this code example. This function requires an execution role that has permissions to access the S3 bucket, the DynamoDB table, and establish a CloudWatch log group in order for it to be executed successfully. It also requires a Resource-based Policy in order for SES to be able to call the Lambda function. As a final step, when we configure SES to call the lambda function, SES automatically adds the necessary permissions to the function, which are specified in this article. The following is an example of a policy statement:

When you include a Lambda action in a receipt rule, Amazon SES sends an event record to Lambda every time an incoming message is received. While this event contains information about the email headers for the incoming message, it does not contain information about the results of the tests (spam filtering and virus scanning) that Amazon SES performs on incoming messages. Additionally, it does not contain information about the body of the incoming message. The lambda function must process the body of an email that has been stored in S3 as a result of this. Details on the event may be found here. To demonstrate the functionality of this demo app, we assume that the item name is included in the subject and that the amount of each item is included in its body, and that this information is written to the DynamoDB table.

Step 4:  Configure SES to send emails to S3 and activate Lambda functions in response to those emails Function

The final step is to set up Amazon SES (Simple Email Service). The first step is to verify a domain name so that SES may use it to send and receive emails. Verifying your domain ownership ensures that you are the legitimate owner of the domain and are therefore authorised to handle the sending and receiving of emails from addresses associated with the domain. To check the validity of your domain name, please do the following:

  • Domains can be found under the Identity Management section of the navigation pane in the SES console.
  • Select Verify new Domain from the drop-down menu.
  • In the Verify new Domain dialogue box, type in the domain name you want to verify.

Select Verify This Domain from the drop-down menu.

  • An entry for Domain verification record set will be displayed in the dialogue box. You must add this record to the domain DNS server in order for it to function properly. In addition, you will need to add an email receiving record (MX Record) to your domain DNS server’s configuration.
  • As long as your DNS server is Route53, and it is registered under the same account as your SES account, SES will provide you with the option to update it directly from within the SES console.

Once the domain is verified its status switches from “pending verification” to “verified” and now it can used it to send and receive emails.

Create a rule set for the recipients after that. The Rule Set allows you to specify what SES should behave with emails that come from domains that you own. You have the option of creating rules for specific addresses or for any address within a domain. To construct the Rule Set, follow these steps:

  • Rule Sets can be found in the Email Receiving section of the left navigation pane.
  • Create a rule by selecting it from the drop-down menu.
  • Enter the email address of the recipient for whom you wish to configure the rule. You can add up to a maximum of 100 recipient addresses or just set it up for any address in the domain using just the domain name as a wildcard.

Once the addresses have been entered, go to the next step, which is to enter the rules actions. Include the following two actions:

The first is of the type S3, and it is used to save a copy of the email to the S3 bucket that was created in step 1. From the drop-down list, select the bucket name that you created in step 1. As an alternative, you can add a prefix to the filename in order to categorise the output of various rules.

  1. The second is of type Lambda, and it is used to trigger the lambda that will be responsible for processing the email. From the drop-down list, select the lambda that was created in step 3.

Once the SES Rule has been configured, we will have the complete workflow in operation. The Lambda will now process any emails delivered to the [email protected] address. You can configure email processing to be a part of your application’s workflow in this way, without having to poll the application for updates.

Need help on AWS?

AWS Partners, such as AllCode, are trusted and recommended by Amazon Web Services to help you deliver with confidence. AllCode employs the same mission-critical best practices and services that power Amazon’s monstrous ecommerce platform.

Conclusion

The goal of this post was to demonstrate that it is possible to integrate email processing into an application workflow without the need to poll a mailbox.

It is possible to create a serverless architecture by using SES to receive emails. This allows emails to be processed and checked for spam and viruses, after which the output can be sent to any downstream system or stored in a database for application use.

As a trusted AWS Partner, AllCode’s team of experts is here to help you with any questions you may have about Amazon Web Services. To learn more about other Amazon Web Services, check out our AWS Partner Menu!

Free AWS Services Template
Text AWS to (415) 223-9212
Text us and join the 700+ developers that have chosen to opt-in to receive the latest AWS insights directly to their phone. Don’t worry, we’ll only text you 1-2 times a month and won’t send you any promotional campaigns - just great content!

Related Articles

App Development: Choosing the Programming Language

App Development: Choosing the Programming Language

When thinking about programming languages, frameworks, and SDKs for mobile web app development, you should consider the front-end (UI) development environment as well as the back-end (server-side) development environment.

What is Tigera?

What is Tigera?

An AWS Advanced Technology Partner, Tigera delivers Calico and Calico Enterprise for security and networking on EKS, both of which are AWS Containers Competency certified.

Centro Community Partners

Centro Community Partners

Centro Community Partners (Centro) is a nonprofit organization that provides programs and resources to help underserved entrepreneurs start, develop and grow their small businesses. Centro also offers technology and curriculum to other organizations and trainers through their Entrepreneurship Suite.

Vezt

Vezt

Blockchain technology has the potential to be a windfall for musicians, filmmakers, and video game developers. With the advent of new technology, the way we consume entertainment is changing. Vezt assists artists in distributing their tracks on digital channels and in promoting their work.

Free AWS Services List

Download this FREE list of all 200+ AWS services and ensure that you're using the optimal services for your use case to enhance efficiency and save money!

Free AWS Business Continuity Plan Template

Make sure you have the proper business continuity plan explicitly for you AWS infrastructure. our professionals built this template using AWS best practices so you can ensure it's built to scale! 

Free Cloud Migration Checklist

Without the proper cloud migration strategy, you risk losing time and money. Ensure that your migration process is running smoothly with our FREE cloud migration checklist.

Free AWS Services List

You might be optimizing with the wrong AWS services. Download this FREE list of all 200+ AWS services and ensure that you're using the optimal services for your use case to enhance efficiency and save money!

Download your FREE AWS Business Continuity Plan Template
Download Free 200+ AWS Services Checklist
Download our 10-Step Cloud Migration ChecklistYou'll get direct access to our full-length guide on Google Docs. From here, you will be able to make a copy, download the content, and share it with your team.