AWS Messaging & Targeting Blog
How to use domain with Amazon SES in multiple accounts or regions
Sometimes customers want to use their email domain with Amazon Simples Email Service (Amazon SES) across multiple accounts, or the same account but across multiple regions.
For example, AnyCompany is an insurance company with marketing and operations business units. The operations department sends transactional emails every time customers perform insurance simulations. The marketing department sends email advertisements to existing and prospective customers. Since they are different organizations inside AnyCompany, they want to have their own Amazon SES billing. At the same time, they still want to use the same AnyCompany domain.
Other use-cases include customers who want to setup multi-region redundancy, need to satisfy data residency requirements, or need to send emails on behalf of several different clients. In all of these cases, customers can use different regions, in the same or across different accounts.
This post shows how to verify and configure your domain on Amazon SES across multiple accounts or multiple regions.
Overview of solution
You can use the same domain with Amazon SES across multiple accounts or regions. Your options are: different accounts but the same region, different accounts and different regions, and the same account but different regions.
In all of these scenarios, you will have two SES instances running, each sending email for example.com domain – let’s call them SES1 and SES2. Every time you configure a domain in Amazon SES it will generate a series of DNS records you will have to add on your domain authoritative DNS server, which is unique for your domain. Those records are different for each SES instance.
You will need to modify your DNS to add one TXT record, with multiple values, for domain verification. If you decide to use DomainKeys Identified Mail (DKIM), you will modify your DNS to add six CNAME records, three records from each SES instance.
When you configure a domain on Amazon SES, you can also configure a MAIL FROM domain. If you decide to do so, you will need to modify your DNS to add one TXT record for Sender Policy Framework (SPF) and one MX record for bounce and complaint notifications that email providers send you.
Furthermore, your domain can be configured to support DMAC for email spoofing detection. It will rely on SPF or DKIM configured above. Below we walk you through these steps.
- Verify domain
You will take TXT values from both SES1 and SES2 instances and add them in DNS, so SES can validate you own the domain
- Verify DomainKeys Identified Mail (DKIM)
You will take CNAME values from both SES1 and SES2 instances and add them in DNS, so SES can verify DKIM for your domain
- Complying with DMAC
You will add a TXT value with DMAC policy that applies to your domain. This is not tied to any specific SES instance
- Custom MAIL FROM Domain and SPF
You will take TXT and MX records related from your MAIL FROM domain from both SES1 and SES2 instances and add them in DNS, so SES can comply with DMARC
Here is a sample matrix of the various configurations:
Two accounts, same region | Two accounts, different regions | One account, two regions | |
TXT records for domain verification* | 1 record with multiple values _amazonses.example.com = “VALUE FROM SES1” |
||
CNAMES for DKIM verification | 6 records, 3 from each SES instance record1-SES1._domainkey.example.com = VALUE FROM SES1 |
||
TXT record for DMARC | 1 record. It is not related to SES instance or region _dmarc.example.com = DMARC VALUE |
||
MAIL FROM MX record to define message sender for SES | 1 record for entire region mail.example.com = 10 feedback-smtp.us-east-1.amazonses.com |
2 records, one for each region mail1.example.com = 10 feedback-smtp.us-east-1.amazonses.com |
|
MAIL FROM TXT record for SPF | 1 record for entire region mail.example.com = “v=spf1 include:amazonses.com ~all” |
2 records, one for each region mail1.example.com = “v=spf1 include:amazonses.com ~all” |
* Considering your DNS supports multiple values for a TXT record
Setup SES1 and SES2
In this blog, we call SES1 your primary or existing SES instance. We assume that you have already setup SES, but if not, you can still follow the instructions and setup both at the same time. The settings on SES2 will differ slightly, and therefore you will need to add new DNS entries to support the two-instance setup.
In this document we will use configurations from the “Verification,” “DKIM,” and “Mail FROM Domain” sections of the SES Domains screen and configure SES2 and setup DNS correctly for the two-instance configuration.
Verify domain
Amazon SES requires that you verify, in DNS, your domain, to confirm that you own it and to prevent others from using it. When you verify an entire domain, you are verifying all email addresses from that domain, so you don’t need to verify email addresses from that domain individually.
You can instruct multiple SES instances, across multiple accounts or regions to verify your domain. The process to verify your domain requires you to add some records in your DNS provider. In this post I am assuming Amazon Route 53 is an authoritative DNS server for example.com domain.
Verifying a domain for SES purposes involves initiating the verification in SES console, and adding DNS records and values to confirm you have ownership of the domain. SES will automatically check DNS to complete the verification process. We assume you have done this step for SES1 instance, and have a _amazonses.example.com TXT record with one value already in your DNS. In this section you will add a second value, from SES2, to the TXT record. If you do not have SES1 setup in DNS, complete these steps twice, once for SES1 and again for SES2. This will prove to both SES instances that you own the domain and are entitled to send email from them.
Initiate Verification in SES Console
Just like you have done on SES1, in the second SES instance (SES2) initiate a verification process for the same domain; in our case example.com
- Sign in to the AWS Management Console and open the Amazon SES console.
- In the navigation pane, under Identity Management, choose Domains.
- Choose Verify a New Domain.
- In the Verify a New Domain dialog box, enter the domain name (i.e. example.com).
- If you want to set up DKIM signing for this domain, choose Generate DKIM Settings.
- Click on Verify This Domain.
- In the Verify a New Domain dialog box, you will see a Domain Verification Record Set containing a Name, a Type, and a Value. Copy Name and Value and store them for the step below, where you will add this value to DNS.
(This information is also available by choosing the domain name after you close the dialog box.)
To complete domain verification, add a TXT record with the displayed Name and Value to your domain’s DNS server. For information about Amazon SES TXT records and general guidance about how to add a TXT record to a DNS server, see Amazon SES domain verification TXT records.
Add DNS Values for SES2
To complete domain verification for your second account, edit current _amazonses TXT record and add the Value from the SES2 to it. If you do not have an _amazonses TXT record create it, and add the Domain Verification values from both SES1 and SES2 to it. We are showing how to add record to Route 53 DNS, but the steps should be similar in any DNS management service you use.
- Sign in to the AWS Management Console and open the Amazon Route 53 console.
- In the navigation pane, choose Hosted zones.
- Choose the domain name you are verifying.
- Choose the _amazonses TXT record you created when you verified your domain for SES1.
- Under Record details, choose Edit record.
- In the Value box, go to the end of the existing attribute value, and then press Enter.
- Add the attribute value for the additional account or region.
- Choose Save.
- To validate, run the following command:
dig TXT _amazonses.example.com +short
- You should see the two values returned:
"4AjLMzUu4nSjrz4QVqDD8rXq8X2AHr+JhGSl4foiMmU="
"abcde12345Sjrz4QVqDD8rXq8X2AHr+JhGSl4foiMmU="
Please note:
- if your DNS provider does not allow underscores in record names, you can omit
_amazonses
from the Name. - to help you easily identify this record within your domain’s DNS settings, you can optionally prefix the Value with “
amazonses:
”. - some DNS providers automatically append the domain name to DNS record names. To avoid duplication of the domain name, you can add a period to the end of the domain name in the DNS record. This indicates that the record name is fully qualified and the DNS provider need not append an additional domain name.
- if your DNS server does not support two values for a TXT record, you can have one record named _amazonses.example.com and another one called example.com.
Finally, after some time SES will complete its validation of the domain name and you should see the “pending validation” change to “verified”.
Verify DKIM
DomainKeys Identified Mail (DKIM) is a standard that allows senders to sign their email messages with a cryptographic key. Email providers then use these signatures to verify that the messages weren’t modified by a third party while in transit.
An email message that is sent using DKIM includes a DKIM-Signature header field that contains a cryptographically signed representation of the message. A provider that receives the message can use a public key, which is published in the sender’s DNS record, to decode the signature. Email providers then use this information to determine whether messages are authentic.
When you enable DKIM it generates CNAME records you need to add into your DNS. As it generates different values for each SES instance, you can use DKIM with multiple accounts and regions.
To complete the DKIM verification, copy the three (3) DKIM Names and Values from SES1 and three (3) from SES2 and add them to your DNS authoritative server as CNAME records.
You will know you are successful because, after some time SES will complete the DKIM verification and the “pending verification” will change to “verified”.
Configuring for DMARC compliance
Domain-based Message Authentication, Reporting and Conformance (DMARC) is an email authentication protocol that uses Sender Policy Framework (SPF) and/or DomainKeys Identified Mail (DKIM) to detect email spoofing. In order to comply with DMARC, you need to setup a “_dmarc” DNS record and either SPF or DKIM, or both. The DNS record for compliance with DMARC is setup once per domain, but SPF and DKIM require DNS records for each SES instance.
- Setup “_dmarc” record in DNS for your domain; one time per domain. See instructions here
- To validate it, run the following command:
dig TXT _dmarc.example.com +short
"v=DMARC1;p=quarantine;pct=25;rua=mailto:dmarcreports@example.com"
- For DKIM and SPF follow the instructions below
Custom MAIL FROM Domain and SPF
Sender Policy Framework (SPF) is an email validation standard that’s designed to prevent email spoofing. Domain owners use SPF to tell email providers which servers are allowed to send email from their domains. SPF is defined in RFC 7208.
To comply with Sender Policy Framework (SPF) you will need to use a custom MAIL FROM domain. When you enable MAIL FROM domain in SES console, the service generates two records you need to configure in your DNS to document who is authorized to send messages for your domain. One record is MX and another TXT; see screenshot for mail.example.com. Save these records and enter them in your DNS authoritative server for example.com.
Configure MAIL FROM Domain for SES2
- Open the Amazon SES console at https://console.aws.amazon.com/ses/.
- In the navigation pane, under Identity Management, choose Domains.
- In the list of domains, choose the domain and proceed to the next step.
- Under MAIL FROM Domain, choose Set MAIL FROM Domain.
- On the Set MAIL FROM Domain window, do the following:
-
- For MAIL FROM domain, enter the subdomain that you want to use as the MAIL FROM domain. In our case mail.example.com.
- For Behavior if MX record not found, choose one of the following options:
- Use amazonses.com as MAIL FROM – If the custom MAIL FROM domain’s MX record is not set up correctly, Amazon SES will use a subdomain of
amazonses.com
. The subdomain varies based on the AWS Region in which you use Amazon SES. - Reject message – If the custom MAIL FROM domain’s MX record is not set up correctly, Amazon SES will return a
MailFromDomainNotVerified
error. Emails that you attempt to send from this domain will be automatically rejected.
- Use amazonses.com as MAIL FROM – If the custom MAIL FROM domain’s MX record is not set up correctly, Amazon SES will use a subdomain of
- Click Set MAIL FROM Domain.
You will need to complete this step on SES1, as well as SES2. The MAIL FROM records are regional and you will need to add them both to your DNS authoritative server.
Set MAIL FROM records in DNS
From both SES1 and SES2, take the MX and TXT records provided by the MAIL FROM configuration and add them to the DNS authoritative server. If SES1 and SES2 are in the same region (us-east-1 in our example) you will publish exactly one MX record (mail.example.com in our example) into DNS, pointing to endpoint for that region. If SES1 and SES2 are in different regions, you will create two different records (mail1.example.com and mail2.example.com) into DNS, each pointing to endpoint for specific region.
Verify MX record
Example of MX record where SES1 and SES2 are in the same region
dig MX mail.example.com +short
10 feedback-smtp.us-east-1.amazonses.com.
Example of MX records where SES1 and SES2 are in different regions
dig MX mail1.example.com +short
10 feedback-smtp.us-east-1.amazonses.com.
dig MX mail2.example.com +short
10 feedback-smtp.eu-west-1.amazonses.com.
Verify if it works
On both SES instances (SES1 and SES2), check that validations are complete. In the SES Console:
- In Verification section, Status should be “verified” (in green color)
- In DKIM section, DKIM Verification Status should be “verified” (in green color)
- In MAIL FROM Domain section, MAIL FROM domain status should be “verified” (in green color)
If you have it all verified on both accounts or regions, it is correctly configured and ready to use.
Conclusion
In this post, we explained how to verify and use the same domain for Amazon SES in multiple account and regions and maintaining the DMARC, DKIM and SPF compliance and security features related to email exchange.
While each customer has different necessities, Amazon SES is flexible to allow customers decide, organize, and be in control about how they want to uses Amazon SES to send email.
Author bio
Leonardo Azize Martins is a Cloud Infrastructure Architect at Professional Services for Public Sector. His background is on development and infrastructure for web applications, working on large enterprises. When not working, Leonardo enjoys time with family, read technical content, watch movies and series, and play with his daughter. |
Contributor
Daniel Tet is a senior solutions architect at AWS specializing in Low-Code and No-Code solutions. For over twenty years, he has worked on projects for Franklin Templeton, Blackrock, Stanford Children’s Hospital, Napster, and Twitter. He has a Bachelor of Science in Computer Science and an MBA. He is passionate about making technology easy for common people; he enjoys camping and adventures in nature. |