Opscraft
DNS record types · Lesson 3 of 7 · 6 min read

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.

Enlarge diagramsending servermail for@example.compriority 10aspmx.l.google.compriority 20alt1.aspmx.l.google.comtried firstif 10 is down
Figure 1. MX records list the mail servers for a domain. Lower priority numbers are tried first.
Swipe sideways to see all of it, or tap to open it full screen.

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=spf1 TXT 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.

Enlarge diagramp=nonecollect reportsonlyFind everysenderSES, marketing,ticketing, officemailFix alignmentSPF and DKIMfor each onep=quarantinefailures go tospamp=rejectfailures arerefused12345
Figure 2. Rolling out DMARC without blocking your own email.
Swipe sideways to see all of it, or tap to open it full screen.
Enlarge diagramemail arrivesclaims to be fromyouSPFis this sending IP allowed? (TXT onexample.com)DKIMdoes the signature match the key atselector._domainkey?DMARCdo they align with the From domain? what isthe policy?inboxspam folder(quarantine)rejected
Figure 3. How a receiving mail server decides whether to trust your email: three DNS lookups, then a decision.
Swipe sideways to see all of it, or tap to open it full screen.

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.

Enlarge diagram203.0.113.25sending IPmail.example.comname from PTR203.0.113.25A record: matchesPTRAThe PTR lives in 25.113.0.203.in-addr.arpa, controlled by whoever owns the IP block (for EC2, set it via AWS).
Figure 4. Reverse DNS: a PTR record maps an IP back to a name. Mail servers check that the name points forward to the same IP.
Swipe sideways to see all of it, or tap to open it full screen.

Email troubleshooting walkthrough

"Emails from our app go to spam":

  1. Check headers of a delivered message: Authentication-Results shows spf=, dkim=, dmarc=.
  2. SPF: does the record include the actual sending service/IP? Only one SPF record? Under 10 lookups?
  3. DKIM: is the service signing with your domain? Does the selector record exist and match?
  4. DMARC: does the From domain align with the SPF/DKIM domain?
  5. PTR and IP reputation (blocklists), content and sending patterns.