Set up Microsoft Outlook DNS on Cloudflare
This guide shows how to configure DNS records for Microsoft Outlook on Cloudflare, including SPF, DKIM, DMARC, MX, and domain verification records. The fastest way to do this is with the mail2dns CLI, which automatically creates all required records for your domain in seconds.
Setup
If needed, install mail2dns before following the below steps:
npm i -g mail2dns Run the following command and answer the prompts to create DNS records at Cloudflare:
mail2dns setup [YOUR_DOMAIN] outlook cloudflare You will be prompted to input the following values:
-
Microsoft 365 domain verification TXT value
In the Microsoft 365 admin center, go to Settings > Domains, select your domain, and copy the TXT value shown under 'Verify domain' (starts with MS=ms...).
-
DKIM selector1 CNAME target
In the Microsoft 365 admin center under DNS records, find the CNAME record for 'selector1._domainkey' and copy its target value.
-
DKIM selector2 CNAME target
Copy the target value for the 'selector2._domainkey' CNAME record.
-
Cloudflare API token
Create a token at https://dash.cloudflare.com/profile/api-tokens with Zone:DNS:Edit permissions
Set the following environment variables:
MS365_VERIFY_TXT=
MS365_DKIM_SELECTOR1=
MS365_DKIM_SELECTOR2=
CLOUDFLARE_API_TOKEN= Then run the following command to create DNS records at Cloudflare:
mails2dns setup [YOUR_DOMAIN] outlook cloudflare Environment Variables Reference
-
MS365_VERIFY_TXT
Microsoft 365 domain verification TXT value. In the Microsoft 365 admin center, go to Settings > Domains, select your domain, and copy the TXT value shown under 'Verify domain' (starts with MS=ms...).
-
MS365_DKIM_SELECTOR1
DKIM selector1 CNAME target. In the Microsoft 365 admin center under DNS records, find the CNAME record for 'selector1._domainkey' and copy its target value.
-
MS365_DKIM_SELECTOR2
DKIM selector2 CNAME target. Copy the target value for the 'selector2._domainkey' CNAME record.
-
CLOUDFLARE_API_TOKEN
Cloudflare API token. Create a token at https://dash.cloudflare.com/profile/api-tokens with Zone:DNS:Edit permissions
Run the following command, supplying the required options, to create DNS records at Cloudflare:
mails2dns setup [YOUR_DOMAIN] outlook cloudflare --verify-txt [MS365_VERIFY_TXT] --dkim-selector1target [MS365_DKIM_SELECTOR1] --dkim-selector2target [MS365_DKIM_SELECTOR2] --token [CLOUDFLARE_API_TOKEN] Options Reference
-
--verify-txt
Microsoft 365 domain verification TXT value. In the Microsoft 365 admin center, go to Settings > Domains, select your domain, and copy the TXT value shown under 'Verify domain' (starts with MS=ms...).
-
--dkim-selector1target
DKIM selector1 CNAME target. In the Microsoft 365 admin center under DNS records, find the CNAME record for 'selector1._domainkey' and copy its target value.
-
--dkim-selector2target
DKIM selector2 CNAME target. Copy the target value for the 'selector2._domainkey' CNAME record.
-
--token
Cloudflare API token. Create a token at https://dash.cloudflare.com/profile/api-tokens with Zone:DNS:Edit permissions
Passing credentials via flags is not recommended. See protecting secrets.
That's it! After running the setup command, the required DNS records will be created for your domain at Cloudflare to work with Microsoft Outlook.
Optional Flags
-o --no-mx Skip MX records (set up DNS for outbound email only) -y --yes Skip confirmation prompts (the command will error if any required inputs are missing) --allow-insecure-flags Allow secrets to be passed via command-line flags (not recommended) -d --dry-run Show records that would be created without applying them DNS records required for Microsoft Outlook
Microsoft Outlook requires the following DNS records to send and receive email from your domain. These are created automatically by the mail2dns setup command:
TXT Record
@ → {VERIFY_TXT}
MX Record
@ → {DOMAIN_DASHES}.mail.protection.outlook.com
TXT Record
@ → v=spf1 include:spf.protection.outlook.com -all
TXT Record
_dmarc → v=DMARC1; p=none;
CNAME Record
autodiscover → autodiscover.outlook.com
CNAME Record
selector1._domainkey → {DKIM_SELECTOR1_TARGET}
CNAME Record
selector2._domainkey → {DKIM_SELECTOR2_TARGET}
Protecting Secrets
When running the mail2dns setup command, if you provide credentials via flags these will be visible in your shell history and process list.
To avoid this, you can provide credentials via environment variables or interactively. If you understand the risks and still want to provide credentials via flags, you should take steps to ensure that the input is not saved in shell history, and avoid running it on a shared or public machine.
By default, the setup command will error if you provide secrets via flags: to enable them you must opt in by passing the --allow-insecure-flags option, or setting M2D_ALLOW_INSECURE_FLAGS=true environment variable.
Non-interactive mode
You may wish to run the mail2dns setup command without any confirmation prompts (by default, mail2dns asks you to confirm the DNS records it creates before applying them). To do this, use the ‑‑yes or ‑y flag with the setup command. Be sure to review the DNS records that will be created before running the command with this flag, as it will apply all changes without confirmation.
Any mix of flags and environment variables may be used to provide the required values. By default any missing values will be prompted for, or in non-interactive mode the command will produce an error if there are missing required values.
Related Setups
For Microsoft Outlook
- Set up Microsoft Outlook DNS on Amazon Route 53
+
- Set up Microsoft Outlook DNS on Google Cloud
+
- Set up Microsoft Outlook DNS on Vercel
+
- Set up Microsoft Outlook DNS on Azure DNS
+
- Set up Microsoft Outlook DNS on DigitalOcean
+
- Set up Microsoft Outlook DNS on GoDaddy
+
- Set up Microsoft Outlook DNS on Netlify
+
- Set up Microsoft Outlook DNS on Hetzner
+
For Cloudflare
- Set up Google Workspace DNS on Cloudflare
+
- Set up Microsoft 365 DNS on Cloudflare
+
- Set up Amazon SES DNS on Cloudflare
+
- Set up Twilio SendGrid DNS on Cloudflare
+
- Set up Mailgun DNS on Cloudflare
+
- Set up Resend DNS on Cloudflare
+
- Set up Postmark DNS on Cloudflare
+
- Set up Zoho Mail DNS on Cloudflare
+