Email security

How to Setup DKIM: Step-by-Step DNS, Keys and Testing in 2026

DKIM proves your email really came from your domain. Here is the full setup: keys, DNS records, provider steps, testing and rotation — without breaking your mail.

Cysoro Security TeamPublished · 8 min read
v=DKIM1; k=rsap=MIIBIjANBgkq...dkim=pass EMAIL SECURITY SetupDKIM Keys, DNS records and testing.
Quick answer

To set up DKIM, generate a 2048-bit key pair or let your email provider generate one, publish the public key as a TXT record at selector._domainkey.yourdomain.com or publish the CNAME records your provider gives you, enable DKIM signing for outbound mail, then send a test message and confirm the receiving server reports dkim=pass.

Key takeaways

  • DKIM signs mail with a private key and publishes the public key in DNS at selector._domainkey.yourdomain.com.
  • Use a 2048-bit key where supported, and rotate it by publishing a new selector before retiring the old one.
  • DKIM alone does not stop spoofing — pair it with SPF and DMARC at p=reject.

DKIM is the signature on your email. Without it, any receiving server has to take your word that a message really came from your domain — and attackers are very good at sounding convincing.

What is DKIM?

DKIM, DomainKeys Identified Mail, is an email authentication method that adds a cryptographic signature to outgoing messages. The sending server signs selected headers and the body with a private key, and publishes the matching public key in DNS.

Receiving servers use that public key to verify the signature. If the message changed in transit, verification fails. DKIM is defined in RFC 6376, and its cryptographic rules were updated in RFC 8301.

DKIM does not encrypt email, and it does not by itself prove a message is safe. It proves the message came from the domain in the signature and was not altered after signing. That is a narrower claim, and it matters most when combined with SPF and DMARC.

How does DKIM work?

DKIM follows a simple path: sign, publish, verify. Only the first two steps happen on your side; verification happens at every receiving server.

How DKIM works1Signprivate key signs headersand body hash2Publishpublic key in DNS atselector._domainkey3Verifyreceiver checks signatureagainst public keyIf the message changed in transit, verification fails. Illustration by Cysoro.
DKIM in three steps: sign, publish, verify. Illustration by Cysoro.

The sender hashes selected headers and the body, signs that hash with a private key, and adds the result as a DKIM-Signature header. The receiver reads the d= domain and s= selector from that header, looks up selector._domainkey.domain in DNS, and uses the public key to verify the hash.

The signature header carries the details: v= is the version, a= is the algorithm such as rsa-sha256, d= is the signing domain, s= is the selector, h= lists the signed headers, bh= is the body hash and b= is the signature itself. RFC 6376 requires the From header to be signed.

What do you need before you set up DKIM?

Before you touch DNS, list every service that sends email for your domain. Each one needs its own DKIM configuration, and missing one is the most common setup mistake.

  • Your email host: Google Workspace, Microsoft 365, or your mail server.
  • Marketing and transactional senders: your CRM, newsletter tool, help desk and invoicing system.
  • Access to DNS: you need to add TXT or CNAME records at your DNS host.
  • A selector name: something clear such as mail2026 or the provider default such as google.

Also confirm that your DNS host can hold a long TXT record. A 2048-bit RSA public key is a long base64 string, and some hosts split or truncate it. If yours does, use the provider's CNAME option or a shorter key.

How do you set up DKIM step by step?

The process is the same across providers, even though the screens differ. Generate a key, publish the public half, enable signing, then test.

Step 1: Generate the key pair

Most providers generate the key for you. If you run your own mail server, generate a 2048-bit RSA key with OpenSSL, then extract the public key. Keep the private key on the sending server and never publish it.

Use 2048-bit RSA where supported. RFC 8301 says verifiers must not accept signatures from RSA keys under 1024 bits, and RFC 6376 advises 1024 as a minimum with longer keys for long-lived use. Ed25519 is a second signing algorithm added by RFC 8463, but RSA remains the most widely supported.

Step 2: Publish the public key in DNS

Publish the public key as a TXT record at selector._domainkey.yourdomain.com, with a value such as v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA... where the p= value is the full base64 public key with no PEM header or line breaks.

Many providers instead ask you to publish CNAME records that point at their own DNS, so they can rotate the key behind your record. Microsoft 365 does this: it publishes DKIM as CNAMEs, so Microsoft can rotate the key without you changing DNS. Use whichever record type your provider specifies.

The record tags matter: v=DKIM1 is the version and must come first if present, k=rsa is the key type, and p= is the public key. An empty p= means the key is revoked, which is how you retire a selector.

Step 3: Enable DKIM signing

Configure your mail provider to sign outbound mail with the private key and the selector you published. Until you enable signing, the DNS record does nothing.

In Google Workspace, a super administrator goes to Menu, Apps, Google Workspace, Gmail, Authenticate email, picks the domain and clicks Generate new record, then chooses a 2048-bit key. In Microsoft 365, DKIM is enabled per domain in the Defender portal, and signing starts once the CNAME records resolve.

Step 4: Test before you trust it

Send a test message to a Gmail or other external mailbox and check the authentication results in the message headers. You are looking for dkim=pass alongside the correct domain and selector.

Also run a DNS lookup for your selector record and check it with our free DKIM checker. If the record is missing or malformed, the checker will show it before your recipients do.

How do you set up DKIM in Google Workspace?

Google Workspace makes DKIM a guided process, but the DNS step still trips people up. Follow it in order and do not enable signing until DNS has propagated.

  1. In the Admin console, go to Menu, Apps, Google Workspace, Gmail, Authenticate email.
  2. Pick the domain and click Generate new record.
  3. Choose a 2048-bit key if your DNS host supports it, otherwise 1024. Keep the default selector prefix google unless another key already uses it.
  4. At your DNS host, add a TXT record with host google._domainkey and the v=DKIM1; k=rsa; p=... value shown.
  5. Wait for DNS to propagate — Google says up to 48 hours — then return to Authenticate email and click Start authentication.

If you use a third-party sender as well, set up DKIM for that sender separately with its own selector. One DKIM record does not cover every service that sends as your domain.

How do you set up DKIM in Microsoft 365?

Microsoft 365 signs mail from your onmicrosoft.com domain automatically. For your own domain, you must publish its CNAME records and enable signing yourself.

  1. In the Microsoft 365 Defender portal, open Email and collaboration, Policies and rules, Threat policies, Email authentication settings.
  2. Select your domain and open the DKIM settings.
  3. Publish the two CNAME records Microsoft shows you, typically selector1._domainkey and selector2._domainkey pointing at Microsoft's DKIM DNS names.
  4. Wait for the records to resolve, then enable DKIM signing for the domain.
  5. Send a test message and confirm dkim=pass in the headers.

Because Microsoft holds the private keys behind those CNAMEs, it can rotate them without you changing DNS. That is convenient, but it also means you should check periodically that signing is still enabled after tenant changes.

What does a DKIM record look like?

A DKIM record is a list of tag-value pairs separated by semicolons, defined in RFC 6376 Section 3.6.1. Here is the shape, with the key shortened.

TagMeaningExample
v=Version, must be DKIM1 if presentv=DKIM1
k=Key type, rsa by defaultk=rsa
p=Base64 public key, requiredp=MIIBIjANBgkqhkiG9w0...
t=Flags, such as y for testingt=y
h=Allowed hash algorithmsh=sha256
s=Service type, rarely useds=*

A typical record value looks like this: v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA.... Do not split the key across lines in a way your DNS host cannot reassemble, and do not add spaces inside the base64 string.

How do you rotate DKIM keys without breaking mail?

Rotation is where most DKIM setups break. The safe method is overlap: publish the new key before you retire the old one, so there is never a moment when signed mail has no valid public key.

Rotate DKIM keys without a gap1. Generate a new key pair2. Publish the new public key at a new selector3. Switch signing to the new selector4. Wait at least the DNS TTL plus the delivery window5. Revoke the old selector with an empty p= valueNever delete the old record before the new one is live. Illustration by Cysoro.
DKIM rotation: overlap first, revoke last. Illustration by Cysoro.
  1. Generate a new key pair.
  2. Publish the new public key at a new selector.
  3. Configure the sender to sign with the new selector.
  4. Wait at least the DNS TTL plus the delivery window, then confirm recent messages show the new selector.
  5. Revoke the old selector by publishing an empty p= value, or delete the record once you are sure no mail still uses it.

Record the selector owner, creation date, rotation procedure and decommissioning date. Without that log, a future rotation becomes guesswork.

Why is DKIM failing?

DKIM failures are usually DNS or configuration errors, not cryptography problems. Work through the common causes in order.

  • Record not found: the selector name is misspelled, or DNS has not propagated yet. Check the exact name in a DNS lookup.
  • Key mismatch: the private key signing mail does not match the public key in DNS, often after a provider change.
  • Message modified in transit: a forwarding service or mailing list changed headers or the body after signing, breaking the hash.
  • Multiple DKIM signatures: a third-party sender added its own signature with a different domain, and DMARC alignment fails even though DKIM passes.
  • Key too short: a 512-bit or otherwise weak key is rejected by verifiers under RFC 8301.

Check the authentication results header on a received test message first: it tells you whether DKIM passed, failed, or was absent, and which selector was used. That narrows the fault to DNS, signing, or transit.

Never publish your private keyOnly the public key belongs in DNS. If a private key is ever exposed, rotate it immediately using the overlap method above.

How does DKIM work with SPF and DMARC?

DKIM, SPF and DMARC are three parts of one system. SPF checks that the sending server is authorized, DKIM checks that the message was not altered, and DMARC ties both to the domain in the From address and tells receivers what to do when checks fail.

DMARC needs at least one of SPF or DKIM to pass in alignment with your domain. DKIM alignment is usually easier to keep through forwarding than SPF, which is one reason DKIM matters even when SPF is already set up.

Our guide to what DMARC is walks through the safe path from p=none to p=reject.

You can check all three records with the free email security score tool.

The bottom line

Setting up DKIM is a one-time job with lasting value: generate a key, publish the public half in DNS, enable signing, and test until you see dkim=pass. Then rotate on a schedule and keep every sender covered.

DKIM alone will not stop spoofing, but with SPF and DMARC at p=reject it makes your domain far harder to impersonate. Verify your setup now with the free DKIM checker.

Frequently asked questions

What is DKIM in simple terms?

DKIM is a digital signature added to outgoing email. Your mail server signs the message with a private key, and receiving servers check the signature against a public key published in your DNS.

What is a DKIM selector?

A selector is a short name that identifies which key signed a message. It forms part of the DNS name where the public key lives, such as google._domainkey.example.com, so you can run several keys at once.

How long does DKIM take to work?

DNS changes usually propagate within minutes to a few hours, but Google advises allowing up to 48 hours before enabling signing. Test with a real message before you rely on it.

Do I need DKIM if I already have SPF?

Yes. SPF checks the sending server, while DKIM checks that the message content was not changed in transit. They protect different things, and DMARC needs at least one of them to pass in alignment with your domain.

What key size should I use for DKIM?

Use 2048-bit RSA where your provider and DNS host support it. RFC 8301 says verifiers must not accept signatures from RSA keys under 1024 bits, and 1024-bit keys are the minimum.

What happens if DKIM fails?

A DKIM failure alone does not usually reject mail, but it can hurt deliverability and it means DMARC cannot rely on DKIM. Common causes are a missing or mistyped DNS record, a wrong selector, or a message changed in transit.

How often should I rotate DKIM keys?

Rotate at least once a year, and immediately if a private key may have been exposed. Publish the new key at a new selector first, switch signing to it, then revoke the old selector.

Can I use DKIM with multiple email providers?

Yes. Each provider that sends mail for your domain needs its own DKIM configuration and its own selector, so their keys do not clash.

Sources

  1. IETF RFC 6376 — DomainKeys Identified Mail (DKIM) Signatures
  2. IETF RFC 8301 — Cryptographic Algorithm and Key Usage Update to DKIM
  3. Wovu — DKIM setup and rotation: real keys, checked live
  4. Masterly Tech — DKIM Record: What It Is, How It Works, and How to Set It Up
  5. InboxSure — What Is DKIM? How It Works, Setup and Fixing DKIM Failures
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against RFC 6376 and RFC 8301, and against Google Workspace and Microsoft 365 DKIM documentation as summarized in published setup guides.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free