Set up SPF, DKIM and DMARC for Microsoft 365

Step-by-step for Exchange Online: the SPF include, the two DKIM CNAME records and how to enable signing in the Defender portal, then a safe first DMARC record.

Updated

Want to see where your domain stands before you start? Check your domain

Microsoft 365 (Exchange Online) authenticates your outgoing mail once SPF, DKIM and DMARC are published for your custom domain. The DKIM part is where most setups stall: the DNS records are created but signing is never switched on. This guide covers all three records and the switch.

Before you start

You need:

Run the DMARC, SPF and DKIM checker first to see what already exists.

Step 1: SPF

Microsoft publishes the addresses of Exchange Online under spf.protection.outlook.com.

Host / Name Type Value
@ (the bare domain) TXT v=spf1 include:spf.protection.outlook.com -all

Rules:

The Microsoft 365 admin center (Settings → Domains → your domain → DNS records) shows the exact SPF value expected for your tenant.

Step 2: DKIM

Exchange Online uses two selectors, selector1 and selector2, and rotates between them. Each is a CNAME in your DNS pointing to a key Microsoft hosts in your tenant’s onmicrosoft.com domain.

  1. Open the Microsoft Defender portal: security.microsoft.com → Email & collaboration → Policies & rules → Threat policies → Email authentication settings → DKIM tab.
  2. Select your custom domain. If the panel says the CNAME records do not exist yet, click Create DKIM keys. The portal displays the two records to publish.
  3. Publish both CNAMEs. The target names follow this pattern, where your domain’s dots become dashes and tenant is your initial onmicrosoft.com name:
Host / Name Type Value (as shown in the portal)
selector1._domainkey CNAME selector1-yourdomain-com._domainkey.tenant.onmicrosoft.com
selector2._domainkey CNAME selector2-yourdomain-com._domainkey.tenant.onmicrosoft.com
  1. Wait for the records to propagate, then return to the DKIM panel and switch Sign messages for this domain with DKIM signatures to Enabled. If the portal reports that the CNAMEs are missing, wait longer; it checks them live.
  2. Verify with the DKIM checker using the selector selector1,selector2. One of the two selectors shows a key (Microsoft serves only the active one); the other is reported as a CNAME without a key, which is normal.

If you prefer PowerShell, New-DkimSigningConfig -DomainName yourdomain.com -KeySize 2048 -Enabled $true creates the configuration with a 2048-bit key; Rotate-DkimSigningConfig -KeySize 2048 -Identity yourdomain.com upgrades an existing 1024-bit key.

Step 3: DMARC

Start in monitoring mode with a reporting address, so nothing is blocked while you confirm every sender passes.

Host / Name Type Value
_dmarc TXT v=DMARC1; p=none; rua=mailto:dmarc-reports@yourdomain.com

Create the mailbox or a shared mailbox for the reports. Within a day or two, Microsoft, Google, Yahoo and others start sending XML reports; How to read a DMARC report explains them. Once every legitimate source is aligned, follow From p=none to p=reject.

Note that your tenant.onmicrosoft.com domain is separate: Microsoft handles its DKIM, and a DMARC record for it is optional.

Step 4: Verify with a real message

Send a message to an Outlook.com or Gmail address, then view the headers (Outlook: open the message → File → Properties → Internet headers; Gmail: Show original). Look for the Authentication-Results header:

spf=pass (sender IP is 40.107.x.x) smtp.mailfrom=yourdomain.com;
dkim=pass (signature was verified) header.d=yourdomain.com;
dmarc=pass action=none header.from=yourdomain.com

header.d must be your domain, not tenant.onmicrosoft.com. If it is the onmicrosoft.com domain, DKIM signing for the custom domain is not enabled yet.

Common problems

Check your work. Run the checker on your domain: it reads the live DNS records and tells you what is still missing.