跳到正文
DEV Community· dnsplumber·· 23 分鐘前AI 評分49

Amazon SES 電郵 DMARC 失敗?讓 DKIM 和 SPF 與你的網域對齊

Amazon SES mail failing DMARC? Align DKIM and SPF to your domain

AI 導讀

Amazon SES 電郵即使 SPF 通過,DMARC 仍可能失敗,因為 SPF 通過的 amazonses.com 網域未與 From 網域對齊。設定自訂 MAIL FROM 網域及 Easy DKIM,並按指引加入 DNS 記錄,可令 SPF 和 DKIM 分別與寄件網域對齊;發送測試郵件後,可檢查郵件標頭確認結果。

正文

Your app sends through Amazon SES. The code works, the messages go out, and then a receiver reports a DMARC failure.

The confusing part is that SPF passes. It just doesn't pass for you.

Where the alignment breaks

The question is not whether a check passed. It is which domain it passed for.

Without a custom MAIL FROM, SES uses a subdomain of amazonses.com as the Return-Path. SPF checks that domain. So SPF passes, but for amazonses.com, not for your domain. By default, SPF does not align.

DKIM is the other half. It aligns once Easy DKIM is verified for the domain in your From address. Until then, neither check aligns with your domain.

SES needs two pieces of DNS to fix this. Easy DKIM signs mail as your domain. A custom MAIL FROM domain makes SPF match your domain.

The fix

Start in the SES console. Create a domain identity, then copy the records from the identity page. The values below show the shape only, and example.com stands in for your domain.

  1. Add the Easy DKIM records. SES shows three of these, one per token. Copy each value exactly as shown.
   Type:  CNAME
   Name:  <token>._domainkey.example.com
   Value: <token>.<SES signing zone>
  1. Set up a custom MAIL FROM. The subdomain is one you choose. Its MX record receives bounces and complaints.
   Type:  MX
   Name:  <mail-from>.example.com
   Value: 10 feedback-smtp.<region>.amazonses.com
  1. Publish SPF for the MAIL FROM subdomain. This record is for that subdomain only. It does not go into the SPF record at example.com.
   Type:  TXT
   Name:  <mail-from>.example.com
   Value: "v=spf1 include:amazonses.com ~all"
  1. Add a DMARC record, if you don't have one yet. Start with p=none.
   Type:  TXT
   Name:  _dmarc.example.com
   Value: v=DMARC1; p=none; rua=mailto:dmarc@example.com

With these in place, SPF aligns through the custom MAIL FROM, as long as your DMARC record does not set aspf=s. DKIM aligns through Easy DKIM. If you send from a subdomain of the verified domain, DMARC needs relaxed DKIM alignment, so leave out adkim=s.

Strictly, DKIM alignment alone is enough for DMARC to pass. Set up the custom MAIL FROM as well, so that SPF aligns too.

The small things that undo it

A few common mistakes can still undo the setup.

Some DNS hosts append example.com to the name you type, so your domain ends up in the name twice. Enter only the part before your domain, or end the full name with a period. Watch the underscore too: the name is <token>._domainkey, not _<token>._domainkey.

The MAIL FROM MX record deserves a second look. If it is not set up correctly and Behavior on MX failure is set to Use default MAIL FROM domain, SES falls back to a subdomain of amazonses.com, and SPF stops aligning. DKIM still carries DMARC, but you have lost the second check. Keep that subdomain to one MX record as well. More than one makes the setup fail, so don't use it to send or receive other mail.

If you send from a second AWS Region, that Region needs its own verified identity and its own records.

And if your DNS lives on Cloudflare, keep the DKIM CNAMEs DNS only (grey cloud). Cloudflare recommends DNS only for email and domain verification records.

Confirming it worked

DNS records tell you what should happen. A real message tells you what did.

Send yourself a message through SES and look at its headers. You want to see the Return-Path, the DKIM domain, and which of them aligns with your From address. If the Return-Path is now on your MAIL FROM subdomain and the DKIM domain is yours, both checks align.

To check a DKIM key on its own, the selector is the token: the part of the CNAME name before ._domainkey.

The full checklist, with sources, is at https://maildoctor.dev/guides/amazon-ses-spf-dkim-dmarc. To read alignment from a real message, paste its headers into https://maildoctor.dev/tools/email-header-analyzer, which shows the Return-Path, the DKIM domain, and which of them aligns.

Written with AI assistance and checked against the AWS SES documentation.

來源:DEV Community · dev.to