For enterprises of all sizes, email is a critical piece of infrastructure that supports large volumes of communication from an organization. As such, companies need a robust solution to deal with the complexities this may introduce. In some cases, companies have multiple domains that support several different business units and need a distributed way of managing email sending for those domains. For example, you might want different business units to have the ability to send emails from subdomains, or give a marketing company the ability to send emails on your behalf. Amazon Simple Email Service (Amazon SES) is a cost-effective, flexible, and scalable email service that enables developers to send mail from any application. One of the benefits of Amazon SES is that you can configure Amazon SES to authorize other users to send emails from addresses or domains that you own (your identities) using their own AWS accounts. When allowing other accounts to send emails from your domain, it is important to ensure this is done securely. Amazon SES allows you to send emails to your users using popular authentication methods such as DMARC. In this blog, we walk you through 1/ how to comply with DMARC when using Amazon SES and 2/ how to enable other AWS accounts to send authenticated emails from your domain.
DMARC: what is it, why is it important?
DMARC stands for “Domain-based Message Authentication, Reporting & Conformance”, and it is an email authentication protocol (DMARC.org). DMARC gives domain owners and email senders a way to protect their domain from being used by malicious actors in phishing or spoofing attacks. Email spoofing can be used as a way to compromise users’ financial or personal information by taking advantage of their trust of well-known brands. DMARC makes it easier for senders and recipients to determine whether or not an email was actually sent by the domain that it claims to have been sent by.
In this solution, you will learn how to set up DKIM signing on Amazon SES, implement a DMARC Policy, and enable other accounts in your organization to send emails from your domain using Sending Authorization. When you set up DKIM signing, Amazon SES will attach a digital signature to all outgoing messages, allowing recipients to verify that the email came from your domain. You will then set your DMARC Policy, which tells an email receiver what to do if an email is not authenticated. Lastly, you will set up Sending Authorization so that other AWS accounts can send authenticated emails from your domain.
In order to complete the example illustrated in this blog post, you will need to have:
- A domain in an Amazon Route53 Hosted Zone or third-party provider. Note: You will need to add/update records for the domain. For this blog we will be using Route53.
- An AWS Organization
- A second AWS account to send Amazon SES Emails within a different AWS Organizations OU. If you have not worked with AWS Organizations before, review the Organizations Getting Started Guide
How to comply with DMARC (DKIM and SPF) in Amazon SES
In order to comply with DMARC, you must authenticate your messages with either DKIM (DomainKeys Identified Mail), SPF (Sender Policy Framework), or both. DKIM allows you to send email messages with a cryptographic key, which enables email providers to determine whether or not the email is authentic. SPF defines what servers are allowed to send emails for their domain. To use SPF for DMARC compliance you need to set up a custom MAIL FROM domain in Amazon SES. To authenticate your emails with DKIM in Amazon SES, you have the option of:
- Setting up a sending identity, so that Amazon SES automatically adds a DKIM signature to your messages
- Providing Your Own DKIM Authentication Token
- Manually adding your DKIM signature to emails that you send
In this blog, you will be setting up a sending identity.
Setting up DKIM Signing in Amazon SES
- Navigate to the Amazon SES Console
- Select Verify a New Domain and type the name of your domain in
- Select Generate DKIM Settings
- Choose Verify This Domain
- This will generate the DNS records needed to complete domain verification, DKIM signing, and routing incoming mail.
- Note: When you initiate domain verification using the Amazon SES console or API, Amazon SES gives you the name and value to use for the TXT record. Add a TXT record to your domain’s DNS server using the specified Name and Value. Amazon SES domain verification is complete when Amazon SES detects the existence of the TXT record in your domain’s DNS settings.
- If you are using Route 53 as your DNS provider, choose the Use Route 53 button to update the DNS records automatically
- If you are not using Route 53, go to your third-party provider and add the TXT record to verify the domain as well as the three CNAME records to enable DKIM signing. You can also add the MX record at the end to route incoming mail to Amazon SES.
- A list of common DNS Providers and instructions on how to update the DNS records can be found in the Amazon SES documentation
- Choose Create Record Sets if you are using Route53 as shown below or choose Close after you have added the necessary records to your third-party DNS provider.
Note: in the case that you previously verified a domain, but did NOT generate the DKIM settings for your domain, follow the steps below. Skip these steps if this is not the case:
- Go to the Amazon SES Console, and select your domain
- Select the DKIM dropdown
- Choose Generate DKIM Settings and copy the three values in the record set shown
- You may also download the record set as a CSV file
- Navigate to the Route53 console or your third-party DNS provider. Instructions on how to update the DNS records in your third-party can be found in the Amazon SES documentation
- Select the domain you are using
- Choose Create Record
- Enter the values that Amazon SES has generated for you, and add the three CNAME records to your domain
- Wait a few minutes, and go back to your domain in the Amazon SES Console
- Check that the DKIM status is verified
You also want to set up a custom MAIL FROM domain that you will use later on. To do so, follow the steps in the documentation.
Setting up a DMARC policy on your domain
DMARC policies are TXT records you place in DNS to define what happens to incoming emails that don’t align with the validations provided when setting up DKIM and SPF. With this policy, you can choose to allow the email to pass through, quarantine the email into a folder like junk or spam, or reject the email.
As a best practice, you should start with a DMARC policy that doesn’t reject all email traffic and collect reports on emails that don’t align to determine if they should be allowed. You can also set a percentage on the DMARC policy to perform filtering on a subset of emails to, for example, quarantine only 50% of the emails that don’t align. Once you are in a state where you can begin to reject non-compliant emails, flip the policy to reject failed authentications. When you set the DMARC policy for your domain, any subdomains that are authorized to send on behalf of your domain will inherit this policy and the same rule will apply. For more information on setting up a DMARC policy, see our documentation.
In a scenario where you have multiple subdomains sending emails, you should be setting the DMARC policy for the organizational domain that you own. For example, if you own the domain example.com and also want to use the sub-domain sender.example.com to send emails you can set the organizational DMARC policy (as a DNS TXT record) to:
This DMARC policy states that 50% of emails coming from example.com that fail authentication should be quarantined and you want to send a report of those failures to [email protected]. For your sender.example.com sub-domain, this policy will be inherited unless you specify another DMARC policy for our sub-domain. In the case where you want to be stricter on the sub-domain you could add another DMARC policy like you see in the following table.
|1||_dmarc.sender.example.com||TXT||“v=DMARC1;p=reject;pct=100;rua=mailto:[email protected];ruf=mailto:[email protected]”|
This policy would apply to emails coming from sender.example.com and would reject any email that fails authentication. It would also send aggregate feedback to [email protected] and detailed message-specific failure information to [email protected] for further analysis.
Sending Authorization in Amazon SES – Allowing Other Accounts to Send Authenticated Emails
Now that you have configured Amazon SES to comply with DMARC in the account that owns your identity, you may want to allow other accounts in your organization the ability to send emails in the same way. Using Sending Authorization, you can authorize other users or accounts to send emails from identities that you own and manage. An example of where this could be useful is if you are an organization which has different business units in that organization. Using sending authorization, a business unit’s application could send emails to their customers from the top-level domain. This application would be able to leverage the authentication settings of the identity owner without additional configuration. Another advantage is that if the business unit has its own subdomain, the top-level domain’s DKIM settings can apply to this subdomain, so long as you are using Easy DKIM in Amazon SES and have not set up Easy DKIM for the specific subdomains.
Setting up sending authorization across accounts
Before you set up sending authorization, note that working across multiple accounts can impact bounces, complaints, pricing, and quotas in Amazon SES. Amazon SES documentation provides a good understanding of the impacts when using multiple accounts. Specifically, delegated senders are responsible for bounces and complaints and can set up notifications to monitor such activities. These also count against the delegated senders account quotas. To set up Sending Authorization across accounts:
- Navigate to the Amazon SES Console from the account that owns the Domain
- Select Domains under Identity Management
- Select the domain that you want to set up sending authorization with
- Select View Details
- Expand Identity Policies and Click Create Policy
- You can either create a policy using the policy generator or create a custom policy. For the purposes of this blog, you will create a custom policy.
- For the custom policy, you will allow a particular Organization Unit (OU) from our AWS Organization access to our domain. You can also limit access to particular accounts or other IAM principals. Use the following policy to allow a particular OU to access the domain:
“Resource”: “<Arn of Verified Domain>”,
“aws:PrincipalOrgPaths”: “<Organization Id>/<Root OU Id>/<Organizational Unit Id>”
9. Make sure to replace the escaped values with your Verified Domain ARN and the Org path of the OU you want to limit access to.
You can find more policy examples in the documentation. Note that you can configure sending authorization such that all accounts under your AWS Organization are authorized to send via a certain subdomain.
You can now test the ability to send emails from your domain in a different AWS account. You will do this by creating a Lambda function to send a test email. Before you create the Lambda function, you will need to create an IAM role for the Lambda function to use.
Creating the IAM Role:
- Log in to your separate AWS account
- Navigate to the IAM Management Console
- Select Role and choose Create Role
- Under Choose a use case select Lambda
- choose Next: Permissions
- In the search bar, type SES and select the check box next to AmazonSESFullAccess
- Choose Next:Tags and Review
- Give the role a name of your choosing, and choose Create Role
Navigate to Lambda Console
- Select Create Function
- Choose the box marked Author from Scratch
- Give the function a name of your choosing (Ex: TestSESfunction)
- In this demo, you will be using Python 3.8 runtime, but feel free to modify to your language of choice
- Select the Change default execution role dropdown, and choose the Use an existing role radio button
- Under Existing Role, choose the role that you created in the previous step, and create the function
Edit the function
- Navigate to the Function Code portion of the page and open the function python file
- Replace the default code with the code shown below, ensuring that you put your own values in based on your resources
- Values needed:
- Test Email Address: an email address you have access to
- SourceArn: The arn of your domain. This can be found in Amazon SES Console → Domains → <YourDomain> → Identity ARN
- ReturnPathArn: The same as your Source ARN
- Source: This should be your Mail FROM Domain @ your domain
- Your Mail FROM Domain can be found under Domains → <YourDomain> → Mail FROM Domain dropdown
- Ex: [email protected]
- Use the following function code for this example
from botocore.exceptions import ClientError
client = boto3.client('ses')
def lambda_handler(event, context):
# Try to send the email.
#Provide the contents of the email.
response = client.send_email(
'Data': 'This email was sent with Amazon SES.',
'Data': 'Amazon SES Test',
# Display an error if something goes wrong.
except ClientError as e:
print("Email sent! Message ID:"),
- Once you have replaced the appropriate values, choose the Deploy button to deploy your changes
Run a Test invocation
- After you have deployed your changes, select the “Test” Panel above your function code
- You can leave all of these keys and values as default, as the function does not use any event parameters
- Choose the Invoke button in the top right corner
- You should see this above the test event window:
Verifying that the Email has been signed properly
Depending on your email provider, you may be able to check the DKIM signature directly in the application. As an example, for Outlook, right click on the message, and choose View Source from the menu. You should see line that shows the Authentication Results and whether or not the DKIM/SPF signature passed. For Gmail, go to your Gmail Inbox on the Gmail web app. Choose the message you wish to inspect, and choose the More Icon. Choose View Original from the drop-down menu. You should then see the SPF and DKIM “PASS” Results.
To clean up the resources in your account,
- Navigate to the Route53 Console
- Select the Hosted Zone you have been working with
- Select the CNAME, TXT, and MX records that you created earlier in this blog and delete them
- Navigate to the SES Console
- Select Domains
- Select the Domain that you have been working with
- Click the drop down Identity Policies and delete the one that you created in this blog
- If you verified a domain for the sake of this blog: navigate to the Domains tab, select the domain and select Remove
- Navigate to the Lambda Console
- Select Functions
- Select the function that you created in this exercise
- Select Actions and delete the function
In this blog post, we demonstrated how to delegate sending and management of your sub-domains to other AWS accounts while also complying with DMARC when using Amazon SES. In order to do this, you set up a sending identity so that Amazon SES automatically adds a DKIM signature to your messages. Additionally, you created a custom MAIL FROM domain to comply with SPF. Lastly, you authorized another AWS account to send emails from a sub-domain managed in a different account, and tested this using a Lambda function. Allowing other accounts the ability to manage and send email from your sub-domains provides flexibility and scalability for your organization without compromising on security.
Now that you have set up DMARC authentication for multiple accounts in your enviornment, head to the AWS Messaging & Targeting Blog to see examples of how you can combine Amazon SES with other AWS Services!
If you have feedback about this post, submit comments in the Comments section below.