Guide

DKIM. How to Sign Your Email Properly

The cryptographic signature that proves your email came from you. Selectors, key rotation, and the gotchas no one tells you about.

10 min read·Updated May 25, 2026
TL;DR
DKIM cryptographically signs every email so receivers can verify it actually came from your domain and wasn't modified in transit. You publish the public key as a TXT record at <selector>._domainkey.<domain>. Your sending service signs with the matching private key. Get the selector right, use a 2048-bit key, and rotate twice a year.

What DKIM actually is

DKIM (DomainKeys Identified Mail) is a public-key signature scheme bolted onto email. When you send a message, your sending server:

  1. Computes a hash of the message body and selected headers.
  2. Signs that hash with a private key it holds.
  3. Attaches a DKIM-Signature header that includes the signature, the selector, and the domain.

On the receiving side, the mail server fetches your public key from DNS, recomputes the hash, and verifies the signature. If the signature is valid, two things are proven: the message claims to be from your domain are credible, and the signed content hasn't been altered since signing.

Why mailbox providers care

DKIM, unlike SPF, survives forwarding. If a user forwards your transactional email to their personal Gmail, SPF will fail (the forwarding server's IP isn't on your SPF list) but DKIM still validates because the signature is in the message itself. That makes DKIM the more reliable authentication signal for receivers.

DMARC enforcement requires either SPF or DKIM to pass and align. In practice, almost every well-configured sender relies primarily on DKIM alignment because it survives more scenarios than SPF does.

How signing works in practice

DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
    d=example.com; s=google;
    h=from:to:subject:date;
    bh=47DEQpj8HBSa+/TImW+5JC...=;
    b=Zv5kKbZ...=;

The key tags:

  • d= the signing domain (must match or be a parent of the From: domain for DMARC alignment).
  • s= the selector. Receivers will look up <s>._domainkey.<d>.
  • h= which headers were included in the signed hash.
  • bh= the body hash.
  • b= the signature itself.
  • c= canonicalization, how whitespace and case are normalized before hashing.

The DNS record

The public key lives at <selector>._domainkey.<your-domain> as a TXT record:

v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...

Tags you'll see:

  • v=DKIM1, version. Always this.
  • k=rsa, key algorithm.
  • p=, the base64-encoded public key. This is the only required tag.
  • s=, service type (rare, usually omitted).
  • h=, hash algorithms permitted.
  • t=, flags. t=y means "test mode", never deploy with this in production.
Watch out
If p= is empty, that selector is revoked. Some sending platforms automatically revoke keys after a customer leaves; receivers will treat any future message signed with that selector as failed. Don't repurpose an old selector, use a new one.

Picking a selector strategy

Selectors are just labels you choose. Useful conventions:

  • One per service. Google Workspace's selector is typically google. SendGrid uses s1, s2. Postmark uses pm-bounces. Resend uses resend. Don't try to consolidate, each service controls its own private key, so each needs its own published public key.
  • Date-stamped for rotation. If you manage your own keys, 2026-01, 2026-07 is a clean pattern. The selector itself tells you when to rotate.
  • Never reuse a selector across services. Selector default at SendGrid and selector default at Mailgun would collide in your DNS.

Key size and TXT-record gotchas

Use 2048-bit RSA. 1024-bit is acceptable at most receivers but flagged as weak by some auditors, and 1024 is technically breakable by well-resourced adversaries.

A 2048-bit RSA public key, base64-encoded, is around 250 characters, which collides with the 255-character per-string limit in DNS TXT records. Modern DNS providers handle this automatically by splitting the value into multiple quoted strings: "v=DKIM1; k=rsa; p=AAA..." "BBB...". Some receivers concatenate these correctly; some require the split to be in a specific position. If your record refuses to validate, check whether your DNS provider mangled the split.

Note
A few hosting providers truncate TXT records over 255 characters silently. Always verify by querying with dig +short TXT selector._domainkey.example.com from a different network than your DNS provider.

Rotating DKIM keys without downtime

  1. Generate a new private key at your sending service (or your own keygen if you manage it).
  2. Publish the new public key at a new selector, e.g. 2026-07._domainkey.example.com.
  3. Switch the sending service to sign with the new selector.
  4. Wait at least a week. Any mail signed with the old selector and still in transit (delayed retries, mailing lists, archived messages re-routed) will keep validating.
  5. Delete the old DNS record.

Twice a year is industry standard. Annually is fine for low-volume domains. Don't rotate more often than quarterly, the DNS churn isn't worth it.

Common mistakes

  • Selector mismatch. The sending service signs with s=google but the record is published at default._domainkey. Every message fails. Fix: read the actual DKIM-Signature header from a sent message, publish at exactly that selector.
  • Test flag left enabled. t=y in the published record. Some receivers ignore signatures from test-mode keys. Remove it before going live.
  • Body modified after signing. Mailing lists that rewrite subjects, footer-injecting gateways, antivirus appliances that "clean" attachments, all break the body hash. The signature was valid when sent; it's invalid by the time the receiver checks. Use l= body length tags carefully, or accept that DKIM + mailing-list is a known-broken combo (this is part of why ARC exists).
  • Forgetting to verify after rotation. Always send a test message to check-auth@verifier.port25.com or use a tool to confirm a real message validates against the new selector before deleting the old one.

Monitoring DKIM over time

Unlike SPF, DKIM records don't usually change day to day. The failure modes are:

  • Your sending provider rotates their selector and the public key you published goes stale.
  • A DNS migration drops the _domainkey record.
  • You add a new sending service but forget to publish its DKIM record.
  • Someone clicks "revoke" in your sending platform and the p= tag empties.

Continuous monitoring catches all four. DomainsDoc checks the DKIM record for every selector you specify (default set covers the common ones: default, google, selector1, selector2, k1, s1, s2, mail, dkim) and alerts you the moment any of them stop resolving or change keys unexpectedly.

Frequently asked questions

What is a DKIM selector?
A selector is a short label (e.g. "google", "k1", "selector1") that tells receivers where to find the public key. The full DNS record lives at <selector>._domainkey.<your-domain>. Each sending service uses its own selector so you can host multiple DKIM keys side by side.
How do I find my DKIM selector?
Three ways: (1) Check your sending service's DKIM settings, they always show the selector. (2) Open a recent message you sent in Gmail, view source, find the DKIM-Signature header, look for the s= tag. (3) Try the common defaults: google, default, selector1, selector2, k1, mail. Our DKIM checker scans those automatically.
What key size should I use for DKIM?
Use 2048-bit RSA. 1024-bit still works at most receivers but is considered weak. 4096-bit causes DNS UDP packet fragmentation issues at some recursive resolvers, not worth the trade. Ed25519 DKIM is in the spec but most receivers do not validate it yet.
How often should I rotate DKIM keys?
Every 6–12 months is industry practice. To rotate without downtime: publish a new key under a new selector, switch your sending service to sign with the new selector, leave the old selector live for a week so already-queued mail still validates, then delete the old record.
My DKIM record shows up but mail still fails authentication. Why?
Most common causes: (1) The selector in the email signature header does not match what you published, typo, wrong service, or stale config. (2) The key in DNS is truncated (TXT records >255 chars need careful splitting). (3) The body was modified in transit by a mailing list that rewrites content. (4) The header canonicalization mode mismatches what the signer used.
Can I have multiple DKIM records?
Yes, one per selector. Unlike SPF, DKIM is designed for multiple keys. You can sign with one selector while keeping an older one published during a rotation, or have completely separate selectors for different services (transactional vs marketing).
Stop reading. Start monitoring.

Continuous SPF, DKIM, DMARC, blacklist, SSL, and uptime checks. Alerts the moment something breaks.

Start free
Keep reading