SendGrid mail failing DMARC? Align DKIM and SPF to your domain
Your app sends through Twilio SendGrid. The messages go out, and then a receiver reports an SPF, DKIM or DMARC failure. Some recipients also see "via sendgrid.net" next to your From address.
Both come from the same gap: SendGrid is not yet authenticated for your domain.
Where the alignment breaks
DMARC passes only when SPF or DKIM passes for a domain that matches your From address. Until you set up domain authentication, nothing ties SendGrid's SPF and DKIM to your domain.
SendGrid's fix is domain authentication. It is a few CNAME records that put SPF and DKIM on your own domain.
The fix
Start in SendGrid. Open Sender Authentication, start domain authentication, and copy the records it shows. With automated security on, which is the default, they have this shape. example.com stands in for your domain.
- Add the Return-Path CNAME. It carries SPF, and SendGrid keeps it up to date. The
em<nnnn>label is random unless you set a custom return path.
Type: CNAME Name: em<nnnn>.example.com Value: u<id>.wl<id>.sendgrid.net - Add the two DKIM CNAMEs. SendGrid hosts the keys.
Type: CNAME Name: s1._domainkey.example.com Value: s1.domainkey.u<id>.wl<id>.sendgrid.net Type: CNAME Name: s2._domainkey.example.com Value: s2.domainkey.u<id>.wl<id>.sendgrid.net - Add a DMARC record, if you don't have one yet. Start with
p=none. If you already have one, keep yours. A domain has only one DMARC record.
Type: TXT Name: _dmarc.example.com Value: v=DMARC1; p=none; rua=mailto:dmarc@example.com You don't need to change the SPF record at example.com. Automated security adds nothing to it.
Once the CNAMEs verify, both checks align:
- DKIM aligns, because the keys sit under your domain.
- SPF aligns in relaxed mode, because the Return-Path
em<nnnn>.example.comis a subdomain of your From domain. Relaxed is the DMARC default.
Leave aspf=s out of your DMARC record. With strict SPF alignment, the em subdomain does not match your From domain. SendGrid's fixes are to use relaxed alignment, or to send from a subdomain and set a custom return path that matches it.
Strictly, DKIM alignment alone is enough for DMARC to pass. SPF alignment is a second path.
If your DNS host rejects underscores in CNAME names, you can't use automated security. Turn it off. SendGrid then gives you an MX and an SPF TXT record on the em subdomain, plus a DKIM TXT record. You must update these yourself when your account changes.
Link branding is a separate set of CNAMEs for tracked links. It does not affect SPF, DKIM or DMARC.
The small things that undo it
A few common mistakes can still undo the setup.
Some DNS hosts add your domain to the name you type. SendGrid names GoDaddy, Amazon Route 53 and Namecheap. Enter em<nnnn>, not em<nnnn>.example.com.
Subdomains don't inherit authentication from the parent domain. Authenticate the domain that appears in your From address.
If another service already uses the s1 and s2 selectors on your domain, set a custom DKIM selector during setup.
If a custom return path matches an existing CNAME, the new record replaces it. Check your existing records first.
If your DNS lives on Cloudflare, set these CNAMEs to 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.
To check a DKIM key on its own, use https://maildoctor.dev/tools/dkim-checker with the selector s1 or s2.
Then send yourself a message through SendGrid and read its headers. The Return-Path should be on your em subdomain, and DKIM should show your domain. If both are true, both checks align.
If you send marketing mail, there is one more thing to know. With subscription tracking on, SendGrid adds one-click List-Unsubscribe and List-Unsubscribe-Post headers.
The full checklist, with sources, is at https://maildoctor.dev/guides/sendgrid-spf-dkim-dmarc. To read alignment from a real message, paste its headers into https://maildoctor.dev/tools/email-header-analyzer.
Written with AI assistance and checked against the SendGrid documentation.