Skip to content
Deliverability

SPF, DKIM, and DMARC for app developers: setup and troubleshooting

Identify the right DNS names, read the results, and troubleshoot one layer at a time.

THE SHORT ANSWER

SPF authorizes sending servers for an envelope domain. DKIM signs a message using a domain’s key. DMARC connects authenticated identities to the domain readers see in From. A passing check and an aligned identity are related, but different, questions.

Before you start #

For
App developers configuring or diagnosing sending-domain authentication.
Bring
Your provider’s expected records, signing selector and a DNS lookup tool such as dig.
Scope
Commands only read DNS. The header analyzer reads reported results; it does not verify signatures.

First, write down the three identities #

These are illustrative domains. Your provider supplies the real values. A common mistake is inspecting SPF at the visible From domain when the actual envelope sender uses another domain. Another is looking for a DKIM record without knowing its selector.

IdentityExampleWhere to find it
Visible From domainapp.exampleFrom: field shown to the reader
Envelope / return-path domainbounce.app.exampleReturn-Path or provider configuration
DKIM signing domain and selectord=app.example; s=mail1DKIM-Signature header

SPF: check the actual envelope domain #

Query TXT records at the envelope domain and identify the SPF policy. There should be one applicable SPF record at that name. Adding a second record for a new provider is not the same as extending the existing policy.

RFC 7208 limits evaluation to 10 DNS-querying terms across include, a, mx, ptr, exists and redirect; nested evaluation counts too. Exceeding that limit produces permerror. This is not simply a count of TXT records or every DNS packet. The ip4, ip6 and all mechanisms do not spend that term budget. Other limits, including void lookups, still apply. Do not flatten records without a plan to track provider changes.

Two quoted strings on one TXT record are joined into one policy. Two separate TXT records that both begin with v=spf1 are multiple policies and cause an error. Preserve other TXT records, such as domain-verification values, when editing SPF.

Inspect records; these commands do not change DNSshell
dig +short TXT bounce.app.example
dig +short TXT app.example

DKIM: use the selector from the message or provider #

A signature’s s= value selects the key and d= supplies the signing domain. For s=mail1 and d=app.example, inspect mail1._domainkey.app.example. Providers may publish a TXT key directly or use a CNAME that delegates it.

A DNS key can be present while a particular message’s signature fails. The message may have been modified after signing, the wrong key may be in use, or signing may be disabled. Reading DNS alone does not cryptographically verify a message.

For routine key rotation, publish the new selector, allow for DNS caches, then confirm new messages are signed with it. Retain the old public key for an appropriate validation interval so messages already in transit can still be checked. Follow your provider’s rotation procedure; suspected key compromise needs a separate revocation response.

Inspect a known selectorshell
dig +short CNAME mail1._domainkey.app.example
dig +short TXT mail1._domainkey.app.example

Inspect a message’s reported signing domain and selector →

DMARC: look for alignment with the visible From #

DMARC can pass when either SPF or DKIM passes with an aligned domain. Relaxed alignment typically compares organizational domains; strict alignment requires an exact match. A valid DKIM signature from an unrelated provider domain does not by itself align with your From domain.

Start by inspecting _dmarc at the From domain. RFC 9989, published in May 2026, replaces RFC 7489 and uses a DNS Tree Walk for policy discovery and organizational-domain determination. Older implementations can use the earlier public-suffix-list method. Do not treat one parent-domain lookup as a complete DMARC evaluation; use the receiving system’s result and check which discovery rules it implements.

A monitoring policy, p=none, requests no DMARC enforcement action. It is not an instruction to put messages in the inbox. Preserve an existing stronger policy while investigating; weakening it is not a general delivery fix.

Duplicate policy records remain a configuration problem. The current Tree Walk discards multiple DMARC records at a queried name and can continue its search. A diagnostic should report the duplicate records as well as any discovered policy, rather than hiding the bad configuration behind a simple pass label.

Inspect the From domain’s policyshell
dig +short TXT _dmarc.app.example

# Illustrative monitoring policy, not a prescription to replace yours:
# v=DMARC1; p=none

Read authentication results from an actual message →

Work through a forwarded message without changing DNS blindly #

Suppose forwarding changes the connecting IP, so the final receiver reports SPF failure for the original envelope domain. If the aligned DKIM signature survives, DMARC can still pass. If a mailing list changes signed content, that signature may fail too. The repair depends on the path and receiver evidence; adding the forwarder to an unrelated SPF record is not a general solution.

Read Authentication-Results only inside a trust boundary you control or understand. A sender can inject a field with that name. Determine which authserv-id belongs to the receiving infrastructure and how that infrastructure removes or distinguishes untrusted copies; the topmost-looking field alone is not proof.

Synthetic receiver report · assumes mx.receiver.example is trustedtext
From: Receipts <receipts@app.example>
Authentication-Results: mx.receiver.example;
  spf=fail smtp.mailfrom=bounce.app.example;
  dkim=pass header.d=app.example header.s=mail1;
  dmarc=pass header.from=app.example

RFC 8601: the Authentication-Results trust boundary →

Apply sender requirements to your actual traffic #

Google distinguishes requirements for all senders to personal Gmail accounts from requirements for bulk senders. The latter include SPF, DKIM, and DMARC; marketing and subscribed messages have one-click unsubscribe requirements. Check the current sender guidelines for your traffic category instead of treating every transactional email as a marketing subscription.

Authentication is one input to receiving decisions. Recipient expectations, complaints, message formatting, transmission security, and infrastructure also matter. A green DNS check does not override those signals.

Troubleshoot in a fixed order #

Use the free tools to collect evidence, not to generate a universal deliverability score. The header analyzer works locally in your browser. Live DNS checks are not available on the public site yet; use the read-only commands above and your provider’s domain settings.

  1. Confirm the visible From, envelope domain, signing domain, and selector using configuration or a real controlled message.
  2. Query the exact record names. Account for DNS propagation and cached results; distinguish “not found” from a resolver failure.
  3. Compare provider-supplied expected values with what DNS actually returns. Preserve unrelated records and existing mailbox MX routes.
  4. Read the receiving system’s Authentication-Results. A pasted field from an unknown source is not trustworthy evidence.
  5. Resolve the specific issue, then recheck a newly generated controlled message. Keep the earlier evidence for comparison.

Compare passing authentication with aligned authentication #

These simplified examples use From: notices@example.com. Assume example.com and bounce.example.com share the organizational domain determined by the receiver, an applicable DMARC policy exists, and no other signature provides an aligned pass. Authentication alone and DMARC alignment are separate checks.

SPF identityDKIM identityDMARC implication
Pass for unrelated.testPass for d=unrelated.testNeither identity aligns with example.com; two passes are not enough.
FailPass for d=example.comAn aligned DKIM pass can satisfy DMARC.
Pass for bounce.example.comFailSPF can align in relaxed mode; strict SPF alignment needs an exact domain match.
Pass for example.comFailThe SPF identity matches the From domain exactly.

Read the reported identities in email headers →

Reproduce the diagnostic cases #

Run the offline lab before changing a live domain. Its 13 synthetic cases distinguish TXT record shape, lookup failure, trusted receiver evidence and an aligned pass. It uses only Node.js built-ins and sends no email.

The lab accepts alignment and authentication results as explicit assumptions. It does not implement recursive SPF evaluation, DKIM cryptography or DMARC policy discovery. Passing its tests proves the example behaves as described; it says nothing about your real domain.

Synthetic inputExpected interpretationNext check
One TXT record with two stringsJoin the strings without inserting a space.Keep record boundaries when copying DNS output.
Two separate v=spf1 recordsMultiple SPF policies, even if each looks valid.Combine authorized senders into one reviewed policy.
NXDOMAIN or an empty NOERROR answerNo policy at this queried name.Verify the envelope domain; do not edit an unrelated From domain.
SERVFAILLookup error, not proof the record is absent.Capture resolver, name and time; investigate DNS before replacing records.
SPF fails; aligned DKIM passesOne aligned pass can satisfy DMARC.Inspect the trusted receiver report and forwarding path.
SPF and DKIM pass for unrelated domainsPassing authentication does not establish alignment.Compare identities with the visible From domain.
Two signatures; one aligned passThe unrelated signature does not cancel the aligned pass.Retain each signature’s domain, selector and result.
Untrusted report or unresolved policyInsufficient evidence for a DMARC conclusion.Establish the receiver trust boundary and resolve discovery errors.
Run locally · Node.js 22+shell
node --test authentication-diagnostics.mjs

Download the authentication diagnostic lab →

Keep the failed lookup evidence #

Use full dig output when diagnosing a failure: +short hides response status and other context. Save the UTC time, resolver, question, status, answer and TTL. Repeat against the authoritative nameserver for the relevant zone when you need to distinguish stale recursive cache from authoritative data. Delegated DKIM names can involve another zone.

For a missing DKIM key, compare the selector in the affected message with the provider’s active and retired selectors. For a present key and failed signature, preserve the original message for a trusted verifier. Editing SPF cannot repair signed content modified in transit.

Read-only inspection · replace the illustrative namesshell
dig TXT bounce.app.example
dig TXT mail1._domainkey.app.example
dig CNAME mail1._domainkey.app.example
dig TXT _dmarc.app.example

Sources and further reading

Written for Stampwing with AI assistance and checked against the linked documentation. Examples are educational; simulated results are labelled. How these resources are maintained.