Prompt
How do I set up SPF, DKIM, and DMARC for an app email domain?
Latest observation
Here’s the practical way to set up SPF, DKIM, and DMARC for an app sending mail from your domain.
1) Decide which domain/subdomain the app will use
For app email, it’s often best to use a dedicated subdomain, such as:
mail.example.comnotify.example.commg.example.com
This keeps app mail separated from your main business email and makes DNS management easier.
You’ll configure records in the DNS zone for that domain or subdomain.
2) Set up SPF
SPF tells receiving mail servers which services are allowed to send mail for your domain.
What to add
You typically publish one TXT record like:
- Name/Host:
@or your subdomain - Type:
TXT - Value: something like:
v=spf1 include:your-email-provider.example -all
Examples
If your app sends through:
- Google Workspace:
v=spf1 include:_spf.google.com -all - Microsoft 365:
v=spf1 include:spf.protection.outlook.com -all - SendGrid:
v=spf1 include:sendgrid.net -all - Mailgun:
v=spf1 include:mailgun.org -all - Amazon SES:
SES often uses its own MAIL FROM domain setup; SPF may look different depending on the custom MAIL FROM domain you configure.
Important SPF rules
- You should have only one SPF record per domain.
- If you use multiple senders, combine them into one SPF record.
- Keep SPF under the DNS lookup limit of 10 mechanisms/void lookups.
3) Set up DKIM
DKIM signs outgoing messages cryptographically so receivers can verify they weren’t altered and that they’re authorized by your domain.
What to do
Your email provider/app will generate:
- a selector name
- a public key to publish in DNS
You’ll create a TXT record like:
- Name/Host:
selector._domainkey.example.com - Type:
TXT - Value: something like:
v=DKIM1; k=rsa; p=PUBLIC_KEY_HERE
Example
If the selector is app1, the DNS record might be:
- Host:
app1._domainkey.notify.example.com - TXT value: provider-generated DKIM public key
Notes
- Many services let you generate 1 or more DKIM selectors.
- Use 2048-bit keys if supported.
- Make sure your app actually signs outbound messages with DKIM using the same domain/subdomain.
4) Set up DMARC
DMARC tells receivers what to do if SPF/DKIM fail, and gives you reporting.
Start with a monitoring policy
Create a TXT record at:
- Name/Host:
_dmarc.example.com
or_dmarc.notify.example.comif you’re using a subdomain
Example:
v=DMARC1; p=none; rua=mailto:dmarc-reports@example.com; adkim=s; aspf=s
What the tags mean
p=none= monitor only, don’t reject yetrua== aggregate report emailadkim=s= strict DKIM alignmentaspf=s= strict SPF alignment
Then move to enforcement
After you confirm legitimate mail passes:
p=quarantineto send suspicious mail to spamp=rejectto block unauthenticated mail
A common progression is:
p=nonep=quarantinep=reject
5) Make sure alignment works
For DMARC to pass, the domain in the visible From: address must align with SPF and/or DKIM.
Example:
- Visible From:
no-reply@notify.example.com - SPF pass: mail is sent by an authorized service for
notify.example.com - DKIM pass: DKIM signature uses
d=notify.example.com
If your app sends mail as from@example.com but the sending service signs as some other domain, DMARC may fail even if SPF/DKIM individually pass.
6) Test after publishing DNS
After adding DNS records:
- wait for propagation
- send test emails to Gmail, Outlook, Yahoo
- inspect message headers for:
- SPF:
pass - DKIM:
pass - DMARC:
pass
- SPF:
Tools you can use:
- MXToolbox
- dmarcian
- mail-tester.com
- Gmail “Show original”
7) Common mistakes
- Multiple SPF TXT records on the same domain
- Wrong DNS host names for DKIM
- Using
-alltoo early without verifying senders - DKIM key pasted incorrectly
- DMARC set to
rejectbefore testing - From address domain not aligned with SPF/DKIM
Suggested setup for an app
If your app sends notifications from notify.example.com:
SPF
notify.example.com TXT "v=spf1 include:YOUR_PROVIDER -all"
DKIM
selector1._domainkey.notify.example.com TXT "v=DKIM1; k=rsa; p=YOUR_PUBLIC_KEY"
DMARC
_dmarc.notify.example.com TXT "v=DMARC1; p=none; rua=mailto:dmarc@example.com"
If you want, I can also give you:
- the exact DNS records for a specific provider like SendGrid, Mailgun, Amazon SES, Gmail/Google Workspace, or Microsoft 365, or
- a step-by-step setup for a subdomain like
notify.yourdomain.com.