If emails from your domain — order confirmations, password resets, newsletters, or messages from your own mail server — land in spam or are rejected, missing or broken email authentication is the most likely cause. Major mailbox providers such as Gmail, Yahoo and Outlook now require SPF, DKIM and DMARC for bulk senders and increasingly check them for everyone.
This guide explains what each one does and how to set them up, whether you send through your own server or a service.
The three in one sentence each
| Proves | Lives in DNS at | |
|---|---|---|
| SPF | Which servers may send mail for your domain | example.com TXT |
| DKIM | The message was signed by the domain and not altered | selector._domainkey.example.com TXT |
| DMARC | What receivers should do when SPF/DKIM fail, and where to send reports | _dmarc.example.com TXT |
DMARC passes when SPF or DKIM passes and is aligned with the domain in the visible From: address. You need at least one aligned; ideally both.
Step 1: List everything that sends as your domain
Before writing records, make a list:
- Your own mail server or web server (IP addresses).
- Hosted mailboxes (Microsoft 365, Google Workspace, Zoho, etc.).
- Transactional email services (for password resets, orders).
- Newsletter and CRM tools.
- Helpdesk systems and invoicing tools.
Every one of them must be covered by SPF or sign with DKIM, or DMARC will flag their mail.
Step 2: SPF
Publish one TXT record on the domain:
example.com. TXT "v=spf1 ip4:203.0.113.20 include:_spf.example-provider.com -all"
| Mechanism | Meaning |
|---|---|
ip4:203.0.113.20 |
This IPv4 address may send |
a / mx |
The domain’s A / MX hosts may send |
include:domain |
Also allow whatever that domain’s SPF allows (used by providers) |
-all |
Everything else fails (recommended once complete) |
~all |
Everything else “soft fails” (use while testing) |
Rules that catch people out:
- Only one SPF record per domain. Two
v=spf1records = SPF error. Merge them. - Maximum 10 DNS lookups. Each
include,a,mx,existsandredirectcounts, including nested includes inside providers’ records. Exceeding 10 makes SPF fail with a “permerror”. Preferip4:for your own servers. - SPF checks the envelope sender (Return-Path), not the From: header. Many services use their own Return-Path domain, so their SPF passes but is not aligned — that is why DKIM matters.
- Domains that never send email should publish
v=spf1 -all.
Step 3: DKIM
DKIM adds a cryptographic signature to each message. Receivers fetch your public key from DNS to verify it.
For hosted services: each provider gives you one or more DKIM records (often CNAMEs) to add. Add them and enable signing in the provider’s dashboard.
For your own server: generate a key pair. With OpenDKIM:
sudo apt install opendkim opendkim-tools
sudo mkdir -p /etc/opendkim/keys/example.com
sudo opendkim-genkey -b 2048 -d example.com -D /etc/opendkim/keys/example.com -s mail2026 -v
sudo chown -R opendkim:opendkim /etc/opendkim/keys
sudo cat /etc/opendkim/keys/example.com/mail2026.txt
Publish the printed record:
mail2026._domainkey.example.com. TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkq..."
mail2026 is the selector — a label that lets you have several keys and rotate them. Long keys are split into several quoted strings in one TXT record; most DNS panels handle this automatically. Mail server suites such as Mailcow generate and show the DKIM record for you.
Use 2048-bit RSA keys. Rotate keys periodically by publishing a new selector, switching signing to it, and removing the old record later.
Step 4: DMARC
Start in monitoring mode:
_dmarc.example.com. TXT "v=DMARC1; p=none; rua=mailto:dmarc@example.com; fo=1"
| Tag | Meaning |
|---|---|
p= |
Policy: none (monitor), quarantine (spam folder), reject |
rua= |
Where to send daily aggregate reports |
pct= |
Apply the policy to a percentage of failing mail (for gradual rollout) |
adkim= / aspf= |
Alignment: r relaxed (default, subdomains OK) or s strict |
sp= |
Policy for subdomains |
Roll out in stages
p=nonefor 2–4 weeks. Read the reports. Find every legitimate source that fails and fix it (add to SPF, enable DKIM).p=quarantine; pct=25, then increase to 100.p=rejectonce all legitimate mail passes.
Jumping straight to reject usually blocks a forgotten system — invoices or password resets disappear silently.
Reading reports
Aggregate reports arrive as XML attachments from receivers such as Google and Microsoft. They list each sending IP, message counts, and SPF/DKIM/DMARC results. Free and paid DMARC report analysers turn them into readable dashboards; a dedicated mailbox for rua keeps them out of your inbox.
Step 5: The rest of good deliverability
Authentication is necessary but not sufficient:
- Reverse DNS: your sending IP’s PTR record should resolve to a hostname that resolves back to the same IP, and the mail server should introduce itself (HELO) with that name. See reverse DNS explained.
- TLS: your server should offer STARTTLS with a valid certificate.
- Clean IP reputation: check that your IP is not on blacklists — checking IP blacklists.
- Good sending practices: only email people who asked for it, include an unsubscribe link in marketing mail (with the one-click
List-Unsubscribeheader for bulk mail), remove bounces, and keep complaint rates very low. - Gradual warm-up for a new IP: start with small volumes to engaged recipients.
Note that Server.HK has a strict anti-spam policy, and unsolicited bulk email is prohibited on all services. Ports 25/465/587 are open only on US VPS; for most businesses, a professional email provider is the simpler choice for sending.
Testing
- Send to a Gmail account, open the message, choose Show original: it shows SPF, DKIM and DMARC as PASS or FAIL.
- Mail tester services score a test email and show exactly what is wrong.
- Command line checks:
dig TXT example.com +short | grep spf
dig TXT mail2026._domainkey.example.com +short
dig TXT _dmarc.example.com +short
Common mistakes
| Mistake | Effect |
|---|---|
| Two SPF records | SPF permerror; DMARC may fail |
| More than 10 SPF lookups | SPF permerror |
| DKIM record split or truncated by the DNS panel | DKIM fails (“body hash” or “no key”) |
DMARC p=reject before checking reports |
Legitimate mail silently rejected |
| Service sends with your From: but no DKIM for your domain | Fails DMARC alignment |
SPF +all |
Anyone can pass SPF for your domain — never use it |