Guides
How to set up DKIM for your domain
24 October 2026
To set up DKIM, you turn on signing in each service that sends mail for you, then publish the DNS record that service gives you, usually a TXT or CNAME at a name like selector._domainkey.example.com. Receivers use that record to check the signature on every message. You need one setup per sending service, and the signature has to be on your own domain for DMARC to count it.
What DKIM does
RFC 6376 defines DKIM. The sending service signs part of each message with a private key and adds a DKIM-Signature header. The receiver reads two values from that header:
d=, the signing domain, which is the domain taking responsibility for the message.s=, the selector, which picks one key out of several the domain might publish.
It then looks up the public key in DNS at s._domainkey.d. Section 3.6.2.1 of the RFC says all DKIM keys live under the _domainkey subdomain. For d=example.com and s=google, the receiver queries google._domainkey.example.com. If the key verifies the signature, the signed headers and body were not changed after signing.
Selectors exist so one domain can have many keys at once. Section 3.1 says that is how you run several services side by side and how you rotate keys: publish the new one, switch, then retire the old one.
Why the signing domain matters
The RFC does not require d= to match the From address. Many services sign with their own domain by default, and that signature passes DKIM. It does not help your DMARC result, because DMARC needs the signing domain to align with the domain in the From header. The fix is the same for every provider: set up DKIM so the service signs with d= set to your domain.
That is also why the Gmail and Yahoo bulk sender rules keep coming back to alignment. An aligned DKIM pass is the sturdiest way to pass DMARC, because unlike SPF it usually survives forwarding.
Key length
RFC 8301, which updated DKIM in 2018, says signers must use RSA keys of at least 1024 bits and should use at least 2048. It also retired rsa-sha1: it must not be used for signing or verifying. Google requires at least 1024 bits for mail to personal Gmail accounts and recommends 2048 where your DNS host supports it.
Pick 2048 when the service offers a choice. The only common reason not to is a DNS host that cannot store a long TXT value.
Google Workspace
From Google’s Set up DKIM page:
- Sign in to the Admin console as a super administrator. Go to Menu, then Apps, Google Workspace, Gmail, and click Authenticate email.
- Choose your domain and click Generate New Record. Pick 2048 bits if your DNS host supports it, otherwise 1024.
- Leave the selector prefix as
googleunless the domain already has a key with that prefix. - Copy the two values: the host name (
google._domainkey) and the TXT value, which startsv=DKIM1; k=rsa; p=. - At your DNS host, add a TXT record with that host name and value. Do not click Start authentication yet.
- Wait for DNS. Google says it can take up to 48 hours. The console may keep warning you to update DNS during that time.
- Back in Authenticate email, click Start authentication. The status should change to Authenticating email with DKIM.
Google adds two cautions. After turning on Gmail for a new domain, wait 24 to 72 hours before generating the key, or it may fail. And if you route outgoing mail through a gateway, make sure the gateway does not change messages in a way that breaks the signature.
Microsoft 365
Microsoft uses two CNAME records instead of a TXT, so it can rotate keys for you. From Microsoft’s DKIM article:
- In the Microsoft Defender portal, go to Email & collaboration, Policies & rules, Threat policies, Email authentication settings, and the DKIM tab.
- Select your domain and turn the toggle to Enabled. A Client error dialog is expected. Click OK, and the status changes to CnameMissing.
- Open the domain’s details and copy the two CNAME values under Publish CNAMEs.
- At your DNS host, create
selector1._domainkeyandselector2._domainkeyas CNAME records pointing to those values. - Return to the details and turn on Sign messages for this domain with DKIM signatures.
Microsoft’s notes that save time: copy the values exactly, because part of the target is assigned by Microsoft and you cannot build it by hand. Do not publish them as TXT records. On Cloudflare, set both records to DNS only. Microsoft says custom domains get no DKIM signing until you do this. Only the onmicrosoft.com domain is signed automatically, and that does not align with your own. The article also covers PowerShell (New-DkimSigningConfig and Set-DkimSigningConfig) and moving to 2048-bit keys during a rotation.
Every other sender
Newsletter tools, store platforms, help desks, and CRMs follow the same pattern. Look for a page called domain authentication, sender authentication, or DKIM in the service’s settings. It will give you one to three records:
- TXT records hold the public key directly. You maintain them, and a key rotation means editing DNS again.
- CNAME records point to a key the provider hosts. The provider can rotate keys without asking you to change anything.
Add exactly what the service shows, at exactly the names it shows. Then go back to the service and click its verify button. Many will not start signing with your domain until they see the records.
Each service gets its own selector, so records never collide. You can have google._domainkey, selector1._domainkey, and three others on the same domain. There is no limit like SPF’s ten lookups, because a receiver only fetches the one key named in each signature.
DNS host quirks
- Host name: many DNS panels add your domain to the end automatically. Enter
google._domainkey, notgoogle._domainkey.example.com, or you can end up withgoogle._domainkey.example.com.example.com. - Long keys: a 2048-bit key is longer than the 255-character limit for a single TXT string. DNS stores it as several strings that receivers join back together. Most panels split it for you. If yours rejects the value, check its help for long TXT records, or use 1024 bits for that service.
- Pasted characters: a stray space or line break inside the
p=value breaks the key. Paste into a plain text editor first if the value came from a PDF or email.
Check that it works
First confirm the record is visible:
dig TXT google._domainkey.example.com +short
dig CNAME selector1._domainkey.example.com +short
Then send a message from that service to a Gmail address. Google’s DKIM page says not to test by emailing yourself. Open the message, choose More, then Show original, and find the Authentication-Results header. You want dkim=pass with header.d= set to your domain. If it shows the provider’s domain, the service is still signing as itself. Microsoft adds that messages between users in the same Microsoft 365 organization may not carry a signature, so test to an outside address.
If you have DMARC reports coming in, the auth_results section will show your selector and domain with a pass for that service’s IPs within a day or two. Our guide to reading DMARC reports shows where.
Rotating and retiring keys
To replace a TXT key, publish a new selector, switch the service to it, wait for mail signed with the old one to finish arriving, then remove the old record. RFC 6376 section 3.6.1 says a key record with an empty p= means the key has been revoked. That is how you shut off a selector you believe was exposed.
When you stop using a service, remove its DKIM records too. Microsoft also says not to publish DKIM records on parked domains that send no mail. Those should get v=spf1 -all and a DMARC reject policy instead.
Sources
- RFC 6376: DKIM: sections 3.1 (selectors), 3.5 (signature tags), 3.6.1 (key record), 3.6.2.1 (the _domainkey namespace), 3.11 (d= need not match From)
- RFC 8301: DKIM algorithm and key size update
- Google Workspace: Set up DKIM
- Microsoft Learn: Set up DKIM to sign mail from your Microsoft 365 domain
- Google: Email sender guidelines: DKIM key length for Gmail