Skip to content

Set Up SPF, DKIM and DMARC for Microsoft 365

Step-by-step SPF, DKIM and DMARC setup for Microsoft 365 and Exchange Online, with the exact records and how to turn on DKIM signing.

Published 7 min read

To authenticate a custom domain in Microsoft 365, publish SPF with include:spf.protection.outlook.com, create the two DKIM CNAME records (selector1._domainkey and selector2._domainkey) that Microsoft generates for your domain, turn on DKIM signing in the Microsoft Defender portal or with Set-DkimSigningConfig, then publish a DMARC record at _dmarc. Custom domains are not DKIM signed with your domain until you do this, so mail from them cannot pass DMARC through DKIM.

The CNAME targets are specific to your tenant, and Microsoft changed their format for domains added since May 2025. This guide shows how to get the right values and how to confirm everything works.

What Microsoft sets up for you, and what it does not

Every tenant has an initial *.onmicrosoft.com domain. Microsoft manages SPF and DKIM for it. For your own domains, the picture is different:

Record contoso.onmicrosoft.com contoso.com (custom)
SPF Managed by Microsoft You publish it (usually done at enrollment)
DKIM Signed automatically Not signed with your domain until you enable it
DMARC You add it in the Microsoft 365 admin center You publish it at your DNS host

Microsoft has no portal or PowerShell cmdlet for managing SPF or DMARC records in custom domains. Both are created at your DNS host. DKIM is the one record you configure partly inside Microsoft 365.

Before you change anything, run a full domain scan to see what is already published.

Step 1: Publish SPF

If Microsoft 365 is the only service sending mail for the domain, Microsoft's documented record for worldwide tenants is:

contoso.com.  3600  IN  TXT  "v=spf1 include:spf.protection.outlook.com -all"

Government and regional clouds use different includes. Microsoft lists include:spf.protection.office365.us for GCC High and DoD, and include:spf.protection.partner.outlook.cn for Microsoft 365 operated by 21Vianet.

Adding on-premises servers and other senders

Add other sources to the same record. A domain or subdomain can have only one SPF record; two cause a PermError.

contoso.com.  IN  TXT  "v=spf1 ip4:192.0.2.10 include:spf.protection.outlook.com -all"

Microsoft recommends a few practices worth following:

  • Use -all. Microsoft recommends hard fail for Microsoft 365 domains, because DMARC then decides what happens to failing mail.
  • Put bulk senders on a subdomain. Microsoft suggests marketing.contoso.com for services you do not control directly. Each subdomain gets its own SPF record and its own 10-lookup budget.
  • Do not flatten Microsoft's include. Microsoft's sending IPs change often, so replace include:spf.protection.outlook.com with IP addresses at your own risk.
  • Use a TTL of at least 3600 seconds.

Every subdomain you send from needs its own SPF record. The root record does not cover marketing.contoso.com. The SPF guide explains the 10 DNS lookup limit, and the SPF checker counts lookups for you.

Step 2: Set up DKIM

Microsoft 365 uses two selectors for each custom domain, with only one active at a time. The second exists so keys can be rotated without downtime. You publish both as CNAME records that point to keys Microsoft hosts.

The CNAME format

The host names are always the same:

  • selector1._domainkey
  • selector2._domainkey

The targets depend on when the domain was added.

Custom domains added since May 2025 use the newer format:

selector1-<domain-with-dashes>._domainkey.<initial-domain-prefix>.<partition>-v1.dkim.mail.microsoft

For a tenant enrolled as contoso.onmicrosoft.com adding contoso.com, that becomes something like:

selector1._domainkey.contoso.com.  IN  CNAME  selector1-contoso-com._domainkey.contoso.n-v1.dkim.mail.microsoft.
selector2._domainkey.contoso.com.  IN  CNAME  selector2-contoso-com._domainkey.contoso.n-v1.dkim.mail.microsoft.

The <partition> character (n here, r in other tenants) is assigned by Microsoft and cannot be chosen or guessed.

Existing custom domains keep the older format:

selector1._domainkey.contoso.com.  IN  CNAME  selector1-contoso-com._domainkey.contoso.onmicrosoft.com.
selector2._domainkey.contoso.com.  IN  CNAME  selector2-contoso-com._domainkey.contoso.onmicrosoft.com.

Microsoft states that the two formats cannot coexist for the same selector, and that the values in its documentation are illustrations only. Copy the exact values from your tenant, using either method below.

Option A: the Microsoft Defender portal

The steps below match Microsoft's documentation as of this writing. Portal menus move, so check Microsoft's DKIM configuration article if a label differs.

  1. Open the Defender portal at security.microsoft.com and go to Email & collaboration > Policies & rules > Threat policies > Email authentication settings. The direct link is security.microsoft.com/authentication.
  2. Select the DKIM tab.
  3. In the row for your domain, slide the Toggle to Enabled. A Client error dialog opens because the CNAMEs do not exist yet. This is expected.
  4. Close the dialog. The domain's Status is now CnameMissing.
  5. Click the row (not the check box or the toggle) to open the details flyout. Copy the values in the Publish CNAMEs section.
  6. At your DNS host, create the two CNAME records.
  7. Wait for Microsoft to detect them. Microsoft says this takes a few minutes or longer.
  8. Return to the flyout and turn on Sign messages for this domain with DKIM signatures.

When the records are detected, the toggle stays enabled, the status changes to Valid and Rotate DKIM keys becomes available.

Option B: Exchange Online PowerShell

Connect to Exchange Online PowerShell, then check the current state:

Get-DkimSigningConfig -Identity contoso.com | Format-List Name,Enabled,Status,Selector1CNAME,Selector2CNAME

If the domain has no DKIM configuration yet, create one. -KeySize accepts 1024 (the default) or 2048:

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

Run Get-DkimSigningConfig again, publish the Selector1CNAME and Selector2CNAME values as CNAME records at your DNS host, wait for them to resolve, then enable signing:

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

If Microsoft cannot see the CNAMEs yet, the command fails with an error that repeats the values to publish. Check for typos in the dashes and dots, wait, and run it again.

Key size and rotation

Microsoft's PowerShell default is a 1024-bit key. To move an existing domain to 2048 bits, rotate the keys:

Rotate-DkimSigningConfig -Identity contoso.com -KeySize 2048

Rotation is not immediate. Microsoft says the new key starts signing after four days (96 hours), and the 2048-bit size applies to the selector that becomes active next. A second rotation brings the other selector to 2048 bits. The DKIM guide covers key sizes in general.

Confirm the CNAMEs resolve with the DKIM checker using selectors selector1 and selector2.

Step 3: Publish DMARC

Create a TXT record at _dmarc on each custom domain, starting in monitoring mode:

_dmarc.contoso.com.  3600  IN  TXT  "v=DMARC1; p=none; rua=mailto:dmarc@contoso.com"

Microsoft recommends sending reports to a dedicated mailbox or a Microsoft 365 Group rather than a person's inbox. Use the DMARC generator to build the value.

Microsoft's examples include pct

Microsoft's DMARC article shows records with pct=100 and suggests stepping pct from 10 to 100. RFC 9989, the current DMARC standard, removed pct because values other than 0 and 100 were applied inconsistently. It added t=y (test mode), which asks receivers to apply the policy one level lower. Receivers still on RFC 7489 ignore t, so treat it as a soft signal and plan staged steps by policy level instead. The rollout guide walks through the timing.

Do not forget the onmicrosoft.com domain

If you do not send from your *.onmicrosoft.com domain, Microsoft recommends a reject policy on it too. You add this one in the Microsoft 365 admin center, not at your DNS host:

  1. Go to admin.microsoft.com > Show all > Settings > Domains.
  2. Select the *.onmicrosoft.com domain and open the DNS records tab.
  3. Select Add record, choose TXT, set the name to _dmarc and the value to v=DMARC1; p=reject.
  4. Save.

Step 4: Verify

Send a message from a Microsoft 365 mailbox to an outside address, for example a personal Gmail or Outlook.com account, and read the Authentication-Results header. A healthy result looks like:

Authentication-Results: mx.receiver.example;
  dkim=pass header.d=contoso.com header.s=selector1;
  spf=pass smtp.mailfrom=contoso.com;
  dmarc=pass header.from=contoso.com

The key detail is header.d=contoso.com. If you see header.d=contoso.onmicrosoft.com, signing is still using the initial domain, which does not align with contoso.com. The email headers guide explains every field, and the DMARC checker confirms the published record.

Step 5: Move to enforcement

Read aggregate reports for a few weeks. Fix every legitimate source that fails, then move to p=quarantine and finally p=reject. Microsoft's own rollout advice is to start with low-volume subdomains and save the parent domain for last.

One Microsoft-specific consequence: once your domain publishes p=quarantine or p=reject, outbound Microsoft 365 messages that fail DMARC at the destination are routed through Microsoft's high-risk delivery pool. Microsoft says there is no override. Fix failing senders before you enforce.

How Microsoft 365 handles inbound DMARC

This affects mail your users receive, not mail you send:

  • Inbound handling depends on the Honor DMARC record policy when the message is detected as spoof setting in the anti-phishing policy. With it on, Microsoft documents that p=reject failures are rejected and p=quarantine failures go to Junk Email.
  • Microsoft 365 sends aggregate reports but does not send failure reports, even if a ruf address is published.
  • Aggregate reports are sent only when the receiving domain's MX points directly to Microsoft 365.
  • Forwarded mail and mailing lists can fail DMARC. Microsoft supports trusted ARC sealers for intermediaries you rely on. See email forwarding and ARC.

Troubleshooting

Symptom Likely cause Fix
Status stays CnameMissing CNAMEs not published or mistyped Compare with Get-DkimSigningConfig output
header.d=contoso.onmicrosoft.com Custom domain signing not enabled Enable the toggle or run Set-DkimSigningConfig
SPF PermError Over 10 lookups or two SPF records Merge records, move bulk senders to a subdomain
DMARC passes for Outlook mail, fails elsewhere Third-party senders not aligned Set up aligned DKIM at each third-party sender
No aggregate reports Wrong rua or missing external authorization Check the address and the _report._dmarc record

When the CNAMEs resolve and signing is on, check the whole domain with a free domain scan.

Check your domain now