How to set up DKIM in Office 365 (Microsoft 365): the Defender portal and PowerShell, step by step

Get the two CNAME records, add them to DNS, turn on signing, and confirm your mail is signed with your own domain.

Microsoft 365 signs your mail with DKIM from day one, but only with your onmicrosoft.com address. Mail from your own domain isn't signed with your domain until you set it up, so DKIM can't help DMARC pass for it. Setting it up takes two CNAME records at your DNS host and one switch in the Microsoft Defender portal.

Already added the records? Rigcheck checks that both selectors point to Microsoft and catches doubled names, typos and proxied records.

Before you start

  • Your domain is added to Microsoft 365. You can only set up DKIM for a domain Microsoft 365 already knows about.
  • An admin account that can open the Defender portal at security.microsoft.com and change email authentication settings.
  • Access to your DNS host, wherever your domain's DNS records are managed. That isn't always where you bought the domain. Rigcheck shows your DNS host at the top of your results.
  • One setup per domain. Each custom domain and each subdomain you send from needs its own DKIM setup and its own two records.

Step 1: Get your two CNAME records

  1. In the Microsoft Defender portal, go to Email & collaboration → Policies & rules → Threat policies → Email authentication settings, or open security.microsoft.com/authentication directly.
  2. Select the DKIM tab. Your domain shows with the toggle set to Disabled.
  3. Try to switch the toggle on. Because the records don't exist yet, Microsoft shows a Client error dialog. That's expected: select OK. The domain's status is now CnameMissing, which means Microsoft has made your keys and is waiting for the records.
  4. Click the domain's row (not the toggle) to open its details, and copy the two records under Publish CNAMEs. Leave this panel open; you'll come back to it in Step 3.

If the details panel shows Create DKIM keys instead, select it first. You can also do this whole step in PowerShell; see Using PowerShell instead below.

Step 2: Add the records to your DNS

At your DNS host, create two CNAME records. For a domain added to Microsoft 365 since May 2025, they look like this, with your domain and your onmicrosoft.com name in place of the examples:

Hostselector1._domainkey
TypeCNAME
Valueselector1-yourdomain-com._domainkey.yourtenant.n-v1.dkim.mail.microsoft
Hostselector2._domainkey
TypeCNAME
Valueselector2-yourdomain-com._domainkey.yourtenant.n-v1.dkim.mail.microsoft

The letter before -v1 (here n) is assigned by Microsoft and can differ between domains. Domains set up before May 2025 use an older format that ends in your onmicrosoft.com address instead, such as selector1-yourdomain-com._domainkey.yourtenant.onmicrosoft.com. Both work, but they can't be mixed for the same selector, so copy the values Microsoft shows you rather than typing them from an example.

In the name field, enter only selector1._domainkey and selector2._domainkey. Most DNS hosts add your domain automatically, and typing the full name can produce selector1._domainkey.yourdomain.com.yourdomain.com, which silently fails.

If your DNS is on Cloudflare, set both records to DNS only (grey cloud), not proxied.

Add both records, even though Microsoft only signs with one of them at a time. The second is for key rotation; Office 365 DKIM CNAME records explained covers what each part means.

Step 3: Turn on signing

Give DNS a few minutes, then go back to the details panel you left open and switch Sign messages for this domain with DKIM signatures on. Microsoft says it can take several minutes for the change to show.

When it works, the status reads Signing DKIM signatures for this domain and Rotate DKIM keys becomes available. From then on, Microsoft signs mail from your domain with your domain.

This step is the one people miss. Publishing the records alone doesn't change how your mail is signed.

Using PowerShell instead

If you'd rather not click through the portal, or want to choose the key size, Exchange Online PowerShell does the same three steps. After connecting with Connect-ExchangeOnline, list your domains and their DKIM status:

Get-DkimSigningConfig | Format-List Name,Enabled,Status,Selector1CNAME,Selector2CNAME

If your domain isn't listed, create its keys. This example asks for 2048-bit keys:

New-DkimSigningConfig -DomainName yourdomain.com -Enabled $false -KeySize 2048

Run the first command again. Your domain now shows Enabled: False and Status: CnameMissing. Add the Selector1CNAME and Selector2CNAME values as the two CNAME records in Step 2, then turn signing on:

Set-DkimSigningConfig -Identity yourdomain.com -Enabled $true

If Microsoft can't find the records yet, the command fails with an error that repeats the values to use. Check for typos, wait a little longer and run it again. When it works, the first command shows Enabled: True and Status: Valid.

1024 or 2048 bits?

Choose 2048 bits if you can. Microsoft's PowerShell default is 1024 bits, which Gmail accepts (it requires at least 1024), but Google recommends 2048. To move an existing domain to 2048 bits, rotate its keys with the new size:

Rotate-DkimSigningConfig -Identity yourdomain.com -KeySize 2048

A rotation takes four days (96 hours) to take effect, and you can't start another one in the meantime. Microsoft notes that the new size applies to the selector that becomes active at that rotation; the other selector gets it at the next one. Your two CNAME records don't change.

Step 4: Confirm your mail is signed

  1. Send a message from your domain to an account at another provider, such as a personal Gmail or Outlook.com address. Mail between two addresses in your own organization isn't signed, so it can't show the result.
  2. Open the message's headers. In Gmail, open the message, select the three dots and choose Show original.
  3. In the DKIM-Signature line, d= should be your own domain, and s= should be selector1 or selector2.
  4. In the Authentication-Results line, look for dkim=pass with header.d= your domain.

Paste the headers into Rigcheck's email header analyzer to see SPF, DKIM and DMARC in plain words, including whether DKIM lines up with your From address.

More than one domain, and domains you don't send from

Repeat the steps for each domain and subdomain that sends mail. Microsoft recommends sending bulk or marketing mail from a subdomain, such as news.yourdomain.com, so problems there don't affect your main domain's reputation; that subdomain needs its own DKIM setup.

For domains you own but never send mail from, don't publish DKIM records at all. With no key in DNS, nobody can make a forged message pass DKIM for that domain. A DMARC record with p=reject protects them further.

What to do next

DKIM is what usually makes DMARC pass for Microsoft 365 mail. If you don't have a DMARC record yet, Office 365 DMARC setup, step by step is the next step. For SPF and the full picture, see SPF, DKIM and DMARC for Microsoft 365.

Check your DKIM records. See whether both selectors point to Microsoft, and get the fix if one doesn't.

Check my setup

Browse all guides