Mail records: MX, SPF, DKIM, DMARC, PTR
MX
example.com. 3600 IN MX 10 aspmx.l.google.com.
example.com. 3600 IN MX 20 alt1.aspmx.l.google.com.
MX records list the servers that accept mail for the domain, each with a priority — lower number = preferred. Senders try 10 first, then 20. Equal priorities spread load. MX targets must be hostnames with A/AAAA records.
Why email authentication matters to DevOps
Your platform sends email — alert notifications, password resets, invoices via SES or SendGrid. Without authentication, receivers (Gmail, Outlook) treat it as suspicious and it lands in spam, or attackers can spoof your domain. Since 2024, Gmail and Yahoo require SPF, DKIM and DMARC for bulk senders. Three TXT-based mechanisms work together:
SPF — who may send
example.com. 3600 IN TXT "v=spf1 include:_spf.google.com include:amazonses.com ip4:203.0.113.25 -all"
- Lists servers/services authorised to send mail for the envelope sender domain.
include:pulls in a provider's list;ip4:/ip6:add addresses;-all= hard fail everything else,~all= soft fail.- Exactly one SPF record per name — two
v=spf1TXT records make SPF fail entirely (merge them). - Limit of 10 DNS lookups (includes count) — exceeding it causes
permerror; flatten or reduce includes.
DKIM — signed messages
The sending service signs each message with a private key; receivers fetch the public key from DNS at <selector>._domainkey.<domain>:
google._domainkey.example.com. IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqh...IDAQAB"
s1._domainkey.example.com. IN CNAME s1.domainkey.u123.wl.sendgrid.net.
- Some providers give you a TXT record with the key; others (SES "Easy DKIM", SendGrid) give CNAMEs pointing to keys they host and rotate.
- A TXT string can be at most 255 characters; a 2048-bit key is longer, so the record holds multiple quoted strings that are concatenated:
"v=DKIM1; k=rsa; p=MIIBIjAN..." "...rest of key". Route 53 accepts this format.
DMARC — policy and reporting
_dmarc.example.com. IN TXT "v=DMARC1; p=quarantine; pct=100; rua=mailto:[email protected]; adkim=s; aspf=r"
- Tells receivers what to do when a message fails both SPF and DKIM alignment (the authenticated domain must match the visible From domain):
p=none(monitor only),p=quarantine(spam folder),p=reject(bounce). rua— where to send aggregate reports showing who sends mail as your domain.
Safe DMARC rollout: start with p=none and collect reports → identify every legitimate sender (marketing tools, ticketing, SES, office mail) and fix their SPF/DKIM → move to quarantine (maybe pct=25 first) → reject.
PTR — reverse DNS
PTR records map an IP back to a name, under in-addr.arpa (IPv4, octets reversed) or ip6.arpa:
25.113.0.203.in-addr.arpa. IN PTR mail.example.com.
dig -x 203.0.113.25 +short
Reverse zones are controlled by whoever owns the IP block. Mail receivers check that a sending IP has a PTR that matches a forward A record (forward-confirmed reverse DNS). On AWS you request/set reverse DNS for an Elastic IP used for mail sending (via the console/API); with SES, AWS handles it.
Email troubleshooting walkthrough
"Emails from our app go to spam":
- Check headers of a delivered message:
Authentication-Resultsshowsspf=,dkim=,dmarc=. - SPF: does the record include the actual sending service/IP? Only one SPF record? Under 10 lookups?
- DKIM: is the service signing with your domain? Does the selector record exist and match?
- DMARC: does the From domain align with the SPF/DKIM domain?
- PTR and IP reputation (blocklists), content and sending patterns.