Skip to content
ProgrammableContact

How to set up SPF, DKIM and DMARC for a sending subdomain

By Programmable Contact · Updated · 7 min read

The short answer

Send marketing mail from a subdomain such as news.example.com. Publish your provider's DKIM key under it, point a return-path host (often send.news.example.com) at the provider with an MX and an SPF record, and publish a DMARC record at _dmarc.news.example.com starting with p=none. Then send yourself a message and check its headers for dkim=pass and dmarc=pass with your domain.

Why a subdomain

Mailbox providers judge a sender partly by the domain's history. Marketing mail draws more complaints than receipts and password resets, so keeping it on its own subdomain means a bad campaign doesn't drag down the mail your product depends on. Resend, for one, recommends sending from a subdomain to "isolate your sending reputation". Use a subdomain of the domain people know, like news.example.com, not a lookalike such as example-news.com, which looks suspicious to filters and readers alike.

One caution: reputation isn't fully separate. Gmail's FAQ counts subdomains together toward the 5,000-a-day bulk sender line, and your organisational domain's DMARC policy applies to subdomains that don't publish their own.

What each record does

RecordWhat it provesWhere it lives
SPFThis server may send mail whose return path (envelope sender) is this domainA TXT record on the return-path domain
DKIMThis message was signed by a key published under this domain, and wasn't changedA TXT record at <selector>._domainkey.<domain>
DMARCThe visible From domain matches a domain that passed SPF or DKIM, and what to do if notA TXT record at _dmarc.<domain>
The three checks, in one line each.

SPF and DKIM each check a domain, but not necessarily the one your readers see. DMARC ties them to the From address: it passes when SPF passes and its domain aligns with the From domain, or DKIM passes and its signing domain aligns. Relaxed alignment, the default, counts a subdomain of the same organisational domain as aligned.

Step by step

1. Add the domain at your provider

Add news.example.com (or your choice) in your sending service. It will show you the exact records to publish. The values below are examples of the shape; always copy yours from the provider.

2. Publish the DKIM key

DKIM (example)

Type:  TXT
Name:  resend._domainkey.news.example.com
Value: p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQ…

The part before ._domainkey is the selector your provider uses. Gmail asks for keys of at least 1024 bits and recommends 2048. Some DNS hosts split long TXT values into 255-character strings; that's normal.

3. Set up the return path: MX and SPF

Bounces come back to the return-path address, not your From address. Providers ask you to point a host under your domain at their bounce servers, and publish SPF on that same host.

Return path (example, for a provider sending through Amazon SES)

Type:     MX
Name:     send.news.example.com
Value:    feedback-smtp.us-east-1.amazonses.com
Priority: 10

Type:  TXT
Name:  send.news.example.com
Value: v=spf1 include:amazonses.com ~all

SPF is checked on the return-path domain, so it goes on send.news.example.com, not on your root domain. That also keeps you clear of SPF's limit of ten DNS lookups on the root record, which fills up fast once you add a few services.

4. Publish DMARC

DMARC (to start)

Type:  TXT
Name:  _dmarc.news.example.com
Value: v=DMARC1; p=none; rua=mailto:[email protected]

p=none asks receivers to deliver as usual and send you reports, which is what Gmail, Yahoo and Outlook's bulk sender rules require at a minimum. The rua address receives daily aggregate reports: XML files listing which servers sent mail as your domain and whether it passed. If the report address is on a different domain from the one in the record, that domain has to publish a record agreeing to receive them (RFC 7489, section 7.1).

5. Wait, then verify

DNS changes usually show within minutes to an hour, sometimes longer. Your provider will mark the domain verified once it sees the records. Then send a real message to a Gmail address and open Show original. You want to see:

What a passing message shows

SPF:   PASS with domain send.news.example.com
DKIM:  'PASS' with domain news.example.com
DMARC: 'PASS'

Reading your DMARC reports

Aggregate reports arrive as compressed XML, usually once a day from each large mailbox provider. Each record in one says: this IP sent this many messages claiming to be from your domain, and here is how SPF, DKIM and DMARC came out for them (RFC 7489, section 7.2). You don't need to read the XML by hand; a free report viewer or a spreadsheet will do. What you're looking for:

  • Your provider's servers, passing. The bulk of your volume should show DKIM pass with your domain and DMARC pass. If it doesn't, the DKIM record is missing or mistyped.
  • Other services you forgot. A help desk, a billing tool or a CRM sending as your domain. Each needs its own DKIM key under your domain before you tighten the policy, or its mail will start failing.
  • Forwarded mail. Messages forwarded by a mailing list or a university account often fail SPF and keep DKIM. That's expected, and one reason DKIM matters more.
  • Strangers. Unknown IPs sending as your domain, failing everything, are usually spoofing. They are what a stricter policy stops.

Give it two to four weeks of reports covering your normal sending, including a campaign, before you change anything.

Moving DMARC beyond p=none

p=none meets the rules but doesn't stop anyone pretending to be you. Once a few weeks of reports show every real source of your mail passing, move on in steps:

  1. p=quarantine; pct=25: a quarter of failing mail goes to spam. Watch the reports for anything legitimate failing.
  2. p=quarantine for all failing mail.
  3. p=reject: failing mail is refused outright.

A subdomain inherits the root domain's policy unless it publishes its own, and the root record can set a separate subdomain policy with sp=. If your root domain is already at p=reject, check your sending subdomain passes before your first campaign.

Common mistakes

  • Two SPF records on one name. SPF allows one; two is a permanent error. Merge them into one v=spf1 record.
  • DKIM passes with the provider's domain. It passes but doesn't align. Publish your own DKIM key so mail is signed as your domain.
  • Publishing the full name where the host wants only the prefix. Many DNS panels add your domain for you, so send.news.example.com becomes send.news.example.com.example.com. Enter send.news if your panel works that way.
  • A CNAME at the same name as a TXT or MX. A name with a CNAME can't hold other records.
  • Forgetting reverse DNS and TLS. Gmail asks every sender for valid forward and reverse DNS and TLS. Hosted providers handle these; your own server has to.

Questions

Do I need SPF, DKIM and DMARC on a subdomain?

Yes, if you send from it. DKIM and the return path are set per sending domain, and while a subdomain inherits the root's DMARC policy, publishing its own record lets you get reports for it and set its policy separately.

Is DKIM alone enough for DMARC to pass?

Yes. DMARC passes when either SPF or DKIM passes with an aligned domain. Most providers rely on DKIM, because forwarding often breaks SPF but leaves a DKIM signature intact.

Should SPF end in ~all or -all?

Either is accepted. ~all (soft fail) is the common choice for a return-path subdomain, because DMARC, not SPF alone, decides what happens to failing mail.

How long until DNS records work?

Often minutes, sometimes up to the record's time to live, which can be hours. If a check still fails after a day, look for a typo or a DNS panel that added your domain twice.

Does DMARC p=none hurt delivery?

No. It asks receivers to treat mail as usual and send you reports. It's the minimum Gmail, Yahoo and Outlook ask of bulk senders.

The records, and a check that they're there

When you add a sending domain, Contact shows the four records it needs (DKIM, the return path's MX and SPF, and DMARC) ready to copy, and looks them up over DNS to tell you which are found and which are still missing.