Learn
How to set up DKIM: key, DNS record and first test
How to set up DKIM: create a key and selector, publish the DNS record, turn on signing after it resolves, then confirm dkim=pass in a test message.
Before you start
Here is how to set up DKIM: create a key pair under a selector, publish the public key in your domain's DNS, then turn on signing where your mail is sent from. DKIM (DomainKeys Identified Mail) adds a digital signature to each message, and receivers check it against the public key in DNS. A selector is a label that names one key, so a domain can keep several. Each key lives at selector._domainkey.yourdomain.
You need access to the domain's DNS and admin access to every service that sends mail with your domain in the From address.
What you publish depends on who signs the mail:
| Mail sent from | Who creates the key | What you publish |
|---|---|---|
| Google Workspace | The Admin console | One TXT record, by default at google._domainkey |
| Microsoft 365 | Microsoft | Two CNAME records, selector1._domainkey and selector2._domainkey |
| Amazon SES with Easy DKIM | Amazon SES | Three CNAME records shown in the console |
| Your own mail server | You | One TXT record for the selector you choose |
A CNAME points the name at a host the service runs, where the key is published.
Steps
-
Set the key length and the selector. Choose 2048 bits if your DNS host can store it. On your own server, pick a simple selector, such as
mail1. Use a new selector for each new key, so you never overwrite a key that signed mail still in transit. -
Create the key or copy the records. In Google Workspace, go to Apps, Google Workspace, Gmail, then Authenticate email, and generate a new record. In Microsoft 365, open the DKIM tab under Email authentication settings in the Defender portal and try to enable your domain. The error dialog is expected. The domain's details then list the values under Publish CNAMEs. In Amazon SES, create the domain identity, then copy the records from Publish DNS records. On your own server, create the pair with the DKIM generator and keep the private key on the system that signs. See also DKIM on Google Workspace and DKIM on Microsoft 365.
-
Publish the record at your DNS host. For a TXT key, the name is your selector followed by
._domainkey, and the value follows this format:TXTv=DKIM1; k=rsa; p=YOUR_PUBLIC_KEY
For CNAME records, copy the target as shown, and the name minus the domain if your panel adds it (see below).
-
Wait until the record is visible. Google says DKIM can take up to 48 hours after you add the key, and Amazon SES allows up to 72 hours for DNS changes. Run the lookup under Confirm it worked before you continue.
-
Turn on signing only after that. If a message is signed and the receiver finds no key, the signature fails permanently. With
p=quarantineorp=rejectin your DMARC record, that mail can be quarantined or rejected unless SPF passes and aligns. In Google Workspace, click Start authentication. In Microsoft 365, select Sign messages for this domain with DKIM signatures, which takes effect only once Microsoft detects the CNAME records. Amazon SES finishes on its own when it detects the records. On your own server, give the signing software the private key, the domain and the selector. -
Repeat for each service and domain. Give each service its own selector. Google requires a unique key for each domain.
How to add a DKIM record to your DNS
Keep the underscore in the name. Some DNS panels add your domain on their own. There, leave it out, including from CNAME names shown in full: enter only the part before it, such as mail1._domainkey or selector1._domainkey.
After p=, paste the public key without the BEGIN and END lines or line breaks. A 2048-bit key does not fit in one 255-character string. If your panel won't accept the full value as one string, Google tells you to split it into several quoted strings in the same record, and RFC 6376 has receivers join them with no spaces.
Confirm it worked
-
Look up the record with your own selector and domain. For a CNAME setup, use
-type=CNAME.nslookup -type=TXT google._domainkey.example.com 1.1.1.1The DKIM checker also reads the key and its length.
-
Send a test message to someone on Gmail or Google Workspace. Google says a message to yourself does not verify DKIM.
-
In the recipient's mailbox, open the full headers. In Gmail, next to Reply, click More, then Show original. Paste them into the email header analyzer.
-
Find
Authentication-Resultsand look fordkim=pass. The format varies by receiver, and some showDKIM=OK. -
Check the signing domain in
header.d=. If the receiver shows onlyheader.i=, read thed=tag in theDKIM-Signatureheader instead. For DMARC, thed=domain must align with your From domain: the same organizational domain by default, or an exact match withadkim=s.
Common mistakes
- A TXT record where the service expects a CNAME. Microsoft 365 supports only CNAME records for DKIM. A TXT record at
selector1._domainkeyleaves the status atCnameMissing. - A pass under the service's domain. Microsoft notes that many hosted services sign with the service domain and add your domain only after you configure DKIM. Only the signature aligned with your From domain counts for DMARC.
- Deleting an old key too soon. RFC 6376 describes keeping both public keys published during a transition, while mail signed with the old key may still be in transit. Deleting it early causes DKIM failures.