How to Set Up a DKIM Record for Your Domain

DKIM lives in a DNS TXT record your mail platform generates. Here is where the key comes from, how to publish it, and how to check it worked.

Setting up a DKIM record means publishing one TXT record in your domain's DNS. The record holds a public key. Your mail platform signs each message with the matching private key. The receiving server checks the published key to confirm the mail really came from you. Gmail's guidelines say receiving servers use DKIM to verify that the domain owner actually sent the message.

Where the DKIM key comes from

Usually you do not create the key yourself. Your mail platform or email service provider generates the pair and shows you the DNS record to publish. Most mail platforms have a DKIM page in their settings that produces the record for you.

Gmail's guidelines say if you use an email service provider, verify that they authenticate your domain's email with SPF and DKIM. So before you touch DNS, find that page in your platform and copy the record it gives you. If your platform has no DKIM settings at all, ask it to enable signing, because a record without a signing platform does nothing.

What the DKIM DNS record looks like

The record has three parts you need to understand.

The selector is a short label the platform picks. It goes into the record's host name, before a fixed string. The full host name looks like selector._domainkey.yourdomain.com. The selector lets one domain publish many keys at once. A platform can rotate keys, or two platforms can sign for the same domain without overwriting each other.

The record type is TXT. The value is the public key, a long string starting with v=DKIM1 and continuing with k=rsa and p= followed by the key itself. Copy the whole value exactly. Do not retype it by hand, because one wrong character breaks the signature.

Some platforms also ask for a custom DKIM TXT name, which is just the selector and the _domainkey string combined. If your platform asks for a name and a value separately, the name is the selector part and the value is the key.

Publishing the record at your domain host

Every host's DNS page looks different, but the steps are the same.

  1. Open your domain host's DNS settings and find the area for TXT records.
  2. Paste the host name your platform gave you. Some hosts automatically add the domain name, so if the field already ends with your domain, paste only the selector part, like selector._domainkey. Google Workspace Help gives the same warning for the DMARC record. Some domain hosts automatically add the domain name, so verify the full record name here too.
  3. Set the type to TXT.
  4. Paste the key value into the value field.
  5. Save, and note that DNS changes can take time to spread. Check again later if the first lookup fails.

If your host refuses the record for being too long, contact its support rather than shortening the key yourself.

Key length and provider requirements

Gmail's guidelines say sending to personal Gmail accounts requires a DKIM key of 1024 bits or longer. If your platform offers a choice, take the longer key.

How to check that DKIM is working

Publishing the record is only half the job. Verify it before you rely on it.

First, check the record itself. A DNS lookup tool, or your platform's own verify button, should return the key you published. If the lookup returns nothing, the record may not have spread yet. Or the name may be wrong, because the host appended the domain when you already included it.

Then send a test message to an address you control, at Gmail or another provider. Open the raw source of the message and look for two things.

The DKIM-Signature header shows your platform signed the message and names the selector it used. The Authentication-Results header shows what the receiving server decided. You want a line reading dkim=pass with your domain after it. If that line says dkim=none or dkim=fail, the record is missing or mistyped. Or the platform is signing with a different selector than the one you published.

How DKIM fits with SPF and DMARC

Gmail's guidelines say bulk senders must set up SPF, DKIM, and DMARC for their domain. The three work together, and DMARC is the part that ties SPF and DKIM to the address the reader sees.

SPF checks the sending server against a list you publish. Gmail's guidelines say SPF prevents spammers from sending unauthorized messages that appear to be from your domain. DKIM checks the signature against the key you publish. Either one can authenticate a message on its own.

DMARC then checks alignment. DMARC's standard says a DMARC pass requires an SPF or DKIM pass and that the passing domain be aligned with the Author Domain. Gmail's guidelines say the authenticating domain must be the same domain that appears in the message From: header. That match is what DMARC adds, because SPF or DKIM alone can pass while the From: header shows a different domain.

Alignment has two modes. DMARC's standard says relaxed alignment means the Author Domain and the Authenticated Identifier share the same Organizational Domain. So mail from a subdomain can align with the parent. Strict alignment requires them to be identical.

Google Workspace Help says you must turn on SPF or DKIM for your domain before you can use DMARC. You set up DMARC by adding a DMARC DNS TXT record, with a host value of _dmarc followed by your domain name. Watch for the same host quirk as with DKIM, where the host appends the domain automatically.

Start gently. DMARC's standard says Domain Owners usually start with a policy of p=none and a rua tag pointing to the mailbox that receives aggregate reports. Google Workspace Help recommends the same. The rua tag sends reports to an email address, and the address must include mailto. DMARC's standard says starting at p=none makes sure nothing was missed in the initial SPF and DKIM deployments. The reports let you audit your own mail streams before you tighten the policy.

Gmail's FAQ says bulk senders must set up both SPF and DKIM, but only one needs to be aligned. So a message can pass DMARC through either path, which is why a broken DKIM record sometimes goes unnoticed until SPF breaks too.

Common problems and error codes

Gmail's FAQ says error code 4.7.30 means DKIM authentication didn't pass. Gmail's FAQ says error code 5.7.30 means the message was blocked because it didn't pass DKIM authentication.

Both point at the same short list of causes.

  • The record is missing, or the host name is wrong because the domain got appended twice.
  • The key value has a typo or got truncated when you pasted it.
  • The platform is signing with a selector that has no published record.
  • DNS has not finished spreading yet, so wait and retest before changing anything.

Gmail's guidelines say messages that are not authenticated might be marked as spam or rejected with a 5.7.26 error. That code covers authentication more broadly, so check SPF and DMARC too if you see it.

If mail still lands in spam after DKIM passes

A passing DKIM signature shows your domain signed the mail. It does not prove the mail is wanted. Gmail's guidelines say authenticated messages are less likely to be rejected or marked as spam.

If DKIM passes and mail still lands in spam, look at the rest of the picture. Gmail's guidelines say messages sent from IP addresses on a blocklist are more likely to be marked as spam. Check the list named in any bounce before anything else. A dead list like SORBS tells you nothing either way, so read the bounce text to find a live one.

Volume matters too. Gmail's guidelines say if you send more than 5,000 messages per day, your marketing and subscribed messages must support one-click unsubscribe. That means the List-Unsubscribe headers, not a footer link. Gmail's guidelines say if third-party senders are not in your SPF record, their messages are more likely to be marked as spam. Keep that record current as you add tools.

DKIM is one piece of a working setup. Publish it, verify it, then keep the rest of the chain honest.

Sources

Filed

More filed under SPF and DKIM

  • How to find all DNS records for a domain
  • How to Set Up a DKIM Email Record
  • What a DKIM record is and what each part does
  • Why Your Email Failed SPF and What to Do
  • Can a Domain Have Multiple SPF Records?
  • What It Means When a Domain Has No SPF Record
  • How to Set Up an SPF Record for Your Domain
  • What SPF Email Authentication Checks and Why It Matters
  • How to Set Up a Gmail SPF Record
  • What an SPF Record Is and Where It Goes in DNS
  • SPF record syntax, tag by tag
  • What an SPF Record Is and How to Read Yours