How to set up DKIM signing
Last updated: October 27, 2026
DKIM adds a cryptographic signature to every outgoing message. Your server signs selected headers and the body with a private key; receivers fetch the matching public key from your DNS (selector._domainkey.yourdomain.com) and verify that the message really came from your infrastructure and was not altered in transit.
Unlike SPF, a DKIM signature survives forwarding, which makes it the backbone of DMARC alignment for most senders. Gmail and Yahoo require DKIM for bulk senders, and Gmail additionally uses the DKIM signature to decide which headers to trust — including whether to honor your List-Unsubscribe header.
Setup has three parts: generate a key pair, publish the public half in DNS, and configure your sender to sign. Each part has one classic failure mode, and all three are covered below.
Not sure if this affects you? Run a free domain audit and see the exact check result.
Run the free domain checkStep by step
General procedure
- Choose a selector — a short name that identifies the key, e.g. s1, mail, or 2026q4. Selectors let you run multiple keys and rotate them safely.
- Generate a 2048-bit RSA key pair (1024-bit works but is below current best practice; Ed25519 is supported by some receivers but not universally).
- Publish the public key as a TXT record at <selector>._domainkey.<yourdomain>.com: v=DKIM1; k=rsa; p=<base64 public key>.
- Configure your mail server or ESP to sign with the private key, your domain as d=, and the chosen selector as s=.
- Send a test email and confirm dkim=pass with your d= domain in Authentication-Results.
Google Workspace
- Admin console → Apps → Google Workspace → Gmail → Authenticate email → Generate new record (pick 2048-bit).
- Google shows a TXT record to publish at google._domainkey.yourdomain.com — the default selector is google.
- Publish it, wait for DNS propagation, then click Start authentication. Gmail now signs all outbound mail with d=yourdomain.com.
Microsoft 365
- Defender portal → Email & collaboration → Policies → Threat policies → DKIM, or via PowerShell New-DkimSigningConfig.
- Microsoft asks for two CNAME records (selector1 and selector2) pointing at their infrastructure — they manage the keys and rotation for you.
- Publish both CNAMEs, then enable signing for the domain.
SendGrid / Mailgun / Amazon SES
- SendGrid: Settings → Sender Authentication → authenticate your domain — you publish the CNAMEs they show, they sign with your domain.
- Mailgun: Sending → Domains → your domain → copy the DKIM TXT (usually selector mailo or k1).
- SES: Verified identities → your domain → Easy DKIM → publish the three CNAMEs SES generates.
- In every case the goal is the same: the ESP signs with d=yourdomain.com, not d=esp.com — that is what gives you DMARC alignment.
OpenDKIM / Postfix (self-hosted)
- opendkim-genkey -t -s mail -d example.com creates mail.private and mail.txt (the DNS record).
- Publish mail.txt at mail._domainkey.example.com; configure KeyTable, SigningTable and TrustedHosts; add the milter to Postfix smtpd_milters.
- Set OversignHeaders to include from, to, subject, date, message-id, and list-unsubscribe / list-unsubscribe-post if you send bulk mail.
Copy-paste examples
mail._domainkey TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC..."
DKIM-Signature: v=1; a=rsa-sha256; d=example.com; s=mail; h=from:to:subject:date:message-id:list-unsubscribe; bh=47DEQpj8...; b=K3j9f...
selector1._domainkey CNAME selector1-example-com._domainkey.tenant.onmicrosoft.com
Common mistakes
- Key published at the wrong hostname — must be <selector>._domainkey.<domain>, exactly matching s= and d= in the signature.
- 1024-bit or shorter keys — some receivers distrust them; use 2048-bit.
- h= list too small: headers not listed can be modified in transit without breaking the signature. Critically, if list-unsubscribe is not in h=, Gmail ignores your unsubscribe header.
- DNS record split wrong: long TXT records must be split into ≤255-character quoted strings; many DNS panels do this automatically, some corrupt the key when done by hand.
- Rotating keys by overwriting in place — always bring up the new selector first, keep the old key published until in-flight mail is delivered, then remove it.
- t=y (testing flag) left in the record — verifiers may ignore the signature entirely.
FAQ
What is a DKIM selector?
A name that identifies which key signed the message. The signature says s=mail; d=example.com, so the receiver looks up mail._domainkey.example.com. Multiple selectors let different systems (or key generations) sign concurrently.
DKIM passes but with the ESP's domain — is that enough?
For raw DKIM, yes; for DMARC, no. DMARC alignment requires d= to match your From domain. Configure domain authentication at your ESP so they sign with your domain.
How often should I rotate DKIM keys?
Every 6–12 months is a sane default, and immediately if a private key may have leaked. Rotate by introducing a new selector, never by editing the live record.
Why does Gmail ignore my List-Unsubscribe even though DKIM passes?
Because Gmail only trusts headers covered by the signature. Check the h= tag in DKIM-Signature: list-unsubscribe must be listed there. Passing DKIM with a small h= list does not protect the unsubscribe header.
Do I need DKIM if I already have SPF and DMARC?
Yes — DMARC requires SPF or DKIM to pass with alignment, and SPF routinely breaks on forwarding and mailing lists. DKIM is the mechanism that keeps DMARC passing for forwarded mail.
Fixed it? Prove it.
Send a test email and watch every check go green.
Send a test email to verify the fix