On this page
Why might your legitimate email end up in spam?
Imagine you sent a message from your domain example.com to a customer on Gmail. Before Gmail decides to put your message in the inbox, it asks a simple but decisive question: "Is this message really from example.com, or is someone impersonating the domain name?" The fundamental problem is that the original email protocol (SMTP) was designed in an era when trust was not in question, so it lets any server write any address it likes in the sender field, just as anyone can write your name on an envelope without being you.
This structural flaw is what attackers exploit in phishing messages: they send a message that appears to come from your bank or your company, the recipient is fooled and hands over their details. In turn, mailbox providers (Gmail, Outlook, Yahoo) penalize any domain that does not prove its identity by pushing its messages into spam or rejecting them outright. That is why email authentication is not just a security luxury but a basic requirement for the deliverability of your legitimate email. If you do not set up these records, your perfectly legitimate messages (invoices, order confirmations, welcome emails) may be disappearing into spam without you knowing.
The solution comes in three complementary layers: SPF, which says "only these servers are allowed to send in my name"; DKIM, which adds a digital seal that cannot be forged, proving the message was not tampered with on the way; and DMARC, which combines the two signals, makes the final decision and sends you reports on what is happening. All three records are written as DNS records of type TXT, so it helps to be familiar with the basics of DNS records, simply explained before we dive into the details. If you have not created your professional email yet, start with the guide to setting up professional email on your own domain, then come back here to secure it.
Where do these records live in DNS?
Before going deeper, it helps to draw a mental map of where each record goes. All three records are of type TXT within your domain's DNS zone, but they differ in the "name" (Host/Name) they are placed under. This map alone solves half the problems beginners run into when they put a record under the wrong name.
The first record, SPF, goes on the "root" of the domain itself, that is, the name @ or the bare domain name example.com. The second record, DKIM, does not go on the root but under a special name called the "selector," followed by the fixed part ._domainkey, such as mail._domainkey.example.com. DMARC always goes under the dedicated name _dmarc.example.com. The following table summarizes where each record lives:
| Record | Type | Name (Host) | Answers the question |
|---|---|---|---|
| SPF | TXT | @ (domain root) | Who is allowed to send in my name? |
| DKIM | TXT | selector._domainkey | Is the digital signature valid and the message intact? |
| DMARC | TXT | _dmarc | What do I do with failed messages, and where do I send reports? |
An important note: only one SPF record is allowed per domain (we will explain why later), whereas you can have several DKIM records with different selectors (one for each sending service), and only one DMARC record per domain. Each record is written as a text string in a specific format of "tags" separated by semicolons, and we will explain the format of each one separately.
What is SPF and how does it work?
SPF stands for Sender Policy Framework. Its idea is simple and elegant: you publish in DNS an allowlist of all the servers (IP addresses and domains) permitted to send email in your domain's name. When a mail server receives a message claiming to be from example.com, it checks the IP address of the server that actually sent it, then reads your domain's SPF record and asks: "Is this address on the allowed list?" If it is, SPF passes; if it is not, it fails.
How does the check work, step by step?
When a message arrives, the receiving server looks at the "Envelope From" address (also called MAIL FROM or Return-Path), which is not necessarily the same address you see in the visible "From" field. The server extracts the domain name from this address, then looks up the TXT record starting with v=spf1 for that domain. It then compares the sending server's IP address with the mechanisms listed in the record, one by one, until it finds a match. The first mechanism that matches determines the result.
This is a subtle point that is often overlooked: SPF checks the Return-Path domain, not the visible From domain. That is exactly why DMARC exists, as we will see, because an attacker can set the Return-Path to a domain they own (so SPF passes) while putting your domain in the visible From. SPF alone does not protect the address the user sees.
SPF record syntax and mechanisms
A typical SPF record looks like this:
example.com. IN TXT "v=spf1 include:_spf.google.com include:servers.mcsv.net ip4:203.0.113.10 mx ~all"Each part after v=spf1 is called a "mechanism," and they are read from left to right. The following table explains the most commonly used mechanisms:
| Mechanism | Meaning | Example |
|---|---|---|
include | Import another domain's SPF record (for sending services) | include:_spf.google.com |
a | Allow the address tied to the domain's A record | a or a:mail.example.com |
mx | Allow the mail servers in the domain's MX records | mx |
ip4 | Allow a specific IPv4 address or address range | ip4:203.0.113.10 |
ip6 | Allow a specific IPv6 address | ip6:2001:db8::1 |
all | Matches everything else (always comes last) | ~all or -all |
The symbol before all is called the "qualifier," and it determines how the server treats addresses not included in the list. These differences look small, but they determine how your email behaves entirely:
| Qualifier | Name | Result when there is no match | When to use it |
|---|---|---|---|
-all | Fail (strict rejection) | The message clearly fails SPF | When you fully trust that your list is complete |
~all | SoftFail (lenient) | Accepted but marked as suspicious | During setup and testing |
?all | Neutral | No verdict | Not recommended in practice |
+all | Pass for everyone | Accepts any sender (dangerous!) | Never use it |
The practical recommendation: start with ~all during setup so legitimate messages are not rejected if you forgot a server, then move to -all once DMARC reports confirm that your list is comprehensive. And stay well away from +all, because it cancels all protection and opens your domain to spoofing.
The critical limit: 10 DNS lookups
This is one of the most dangerous constraints in SPF, and many people fall into it without understanding why their email suddenly fails. The specification states that evaluating an SPF record must not exceed 10 DNS lookups. Every mechanism that requires a DNS lookup (include, a, mx, ptr and exists) counts toward this limit. Mechanisms that do not require a lookup, such as ip4, ip6 and all, do not count.
The problem is that every include may import a record that contains another include, so lookups pile up quickly. If you add Google, Mailchimp, a billing provider and a helpdesk tool, you can easily exceed ten. When the limit is exceeded, the result is permerror (a permanent error), and the receiving server may treat it as a failure, dropping your legitimate email. The following table shows which mechanisms use up the limit:
| Mechanism | Counts toward the limit? |
|---|---|
include | Yes (and so does every import inside it) |
a / mx | Yes |
ptr | Yes (and not recommended anyway) |
exists | Yes |
ip4 / ip6 | No |
all | No |
The practical fix when you approach the limit: replace some include mechanisms with explicit ip4 addresses if they are fixed, or use "SPF flattening," which converts the include entries into a direct IP list through a specialized tool that updates it periodically. Most importantly, do not add services you do not actually send from, and clean your record of leftovers from old services.
What is DKIM and how does it sign your messages?
If SPF answers "Where was the message sent from?", DKIM answers a deeper question: "Is this message really from the domain that claims to send it, and did it arrive as it was sent, without changes?" DKIM stands for DomainKeys Identified Mail, and it relies on asymmetric cryptography (a public and a private key), the same principle that SSL certificates are built on.
How does the signature work?
You have a key pair: a private key that stays secret on the sending mail server, and a public key that you publish openly in DNS. When your server sends a message, it takes specific parts of it (selected headers such as From and Subject, plus the message body), computes an encrypted "fingerprint" from them, then signs it with the private key and adds the signature to the message headers as DKIM-Signature.
On receipt, the receiving server reads this header, extracts the selector name and the domain name from it, then looks up in DNS the public key published under selector._domainkey.example.com. Using the public key, it verifies that the signature is valid. If verification succeeds, it proves two things: that the message was signed with the matching private key (that is, it came from a party that controls the server), and that its content has not changed since it was signed. If someone tampered with a single word in the body along the way, verification fails immediately.
The selector and why it matters
The "selector" is an arbitrary name that you (or the sending service) choose so that the same domain can have several DKIM keys. This is useful because every sending service has its own key: Google may use a selector such as google, Mailchimp uses another selector, and your own server a third. Instead of everyone competing for a single name, each one puts its key under its own selector and names that selector inside every message's signature, so the receiver knows where to look.
A DKIM record in DNS looks like this (the public key is usually long and has been shortened here for clarity):
mail._domainkey.example.com. IN TXT "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC7n2x...IDAQAB"Inside the message itself, the signature header looks something like this:
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com;
s=mail; h=from:subject:date:to; bh=...; b=...The following table explains the most important tags in the DKIM record published in DNS:
| Tag | Meaning |
|---|---|
v=DKIM1 | Protocol version (fixed) |
k=rsa | Key algorithm (commonly RSA) |
p=... | The public key itself (the long string) |
t=y | Test mode (optional; tells the receiver you are testing) |
s=email | Service type (optional) |
Expert tip: use 2048-bit keys instead of 1024 whenever possible for stronger security. And note that some DNS panels truncate the long key string, so if you notice DKIM failing even though everything looks right, check that the public key is complete and not cut off. The good thing about DKIM is that, unlike SPF, it survives forwarding in many cases, because the signature is tied to the content, not to the sending IP address.
What is DMARC and how does it tie everything together?
We now reach the last piece of the puzzle. You have SPF checking the sending server and DKIM verifying the signature, but who decides what happens if one of them fails? And who protects the visible From address that the user actually sees? This is where DMARC comes in, short for Domain-based Message Authentication, Reporting and Conformance. Its job is threefold: it ties the SPF and DKIM results to the visible address through the concept of "alignment," it tells the receiver the policy for handling failures, and it sends you periodic reports on everything that is happening.
Alignment: the core of DMARC
This is the most important concept in the whole topic. For DMARC to pass, it is not enough for SPF or DKIM to pass; the domain that passed must be aligned with the domain shown in the visible From field. Remember that SPF checks the Return-Path domain, and that an attacker can make it different from From. Alignment closes this gap:
- SPF alignment (
aspf): theReturn-Pathdomain (where SPF passed) must match the visibleFromdomain. - DKIM alignment (
adkim): the signing domain in DKIM (thed=tag) must match the visibleFromdomain.
DMARC passes if at least one alignment holds (SPF or DKIM). The strictness is set with the aspf and adkim tags: the value r (Relaxed) accepts a match on the organizational domain and subdomains, and the value s (Strict) requires an exact match. This concept is precisely what makes DMARC able to stop spoofing of your domain where SPF and DKIM alone could not.
DMARC record syntax
A typical DMARC record with a gradual rollout looks like this:
_dmarc.example.com. IN TXT "v=DMARC1; p=none; rua=mailto:dmarc@example.com; ruf=mailto:dmarc@example.com; fo=1; adkim=s; aspf=s; pct=100"The following table explains the most important DMARC tags and what each one does:
| Tag | Meaning | Common values |
|---|---|---|
v=DMARC1 | Protocol version (mandatory and the first tag) | DMARC1 |
p | Policy for the main domain | none / quarantine / reject |
sp | Policy for subdomains | none / quarantine / reject |
rua | Address that receives aggregate reports | mailto:dmarc@example.com |
ruf | Address that receives forensic (detailed) reports | mailto:dmarc@example.com |
adkim | DKIM alignment strictness | r (relaxed) / s (strict) |
aspf | SPF alignment strictness | r / s |
pct | Percentage of messages the policy applies to | 0–100 |
fo | When failure reports are sent | 0 / 1 / d / s |
The three policies: none, quarantine and reject
The p tag is the heart of DMARC, and it takes three values representing increasing levels of strictness. Choosing the wrong value at the wrong time can drop your legitimate email, so understanding the difference is essential:
| Policy | What it asks the receiver to do | When to use it |
|---|---|---|
p=none | Monitor and send reports only; take no action | Always at the start, for monitoring and collecting data |
p=quarantine | Put failed messages in spam/quarantine | Once you are sure your legitimate email passes |
p=reject | Reject failed messages outright | The final goal: full protection |
Reports: rua and ruf
DMARC's unique strength is that it gives you back full visibility into what is happening. The rua tag specifies an address that receives aggregate reports: periodic XML files (usually daily) from mailbox providers summarizing how many messages arrived in your domain's name, from which IP addresses, and how many passed or failed SPF, DKIM and alignment. These reports are your eyes on your domain: with them you discover legitimate servers you forgot to add, and you discover who is trying to spoof your domain.
The ruf tag receives forensic (failure) reports: near-real-time copies of failed messages with more detail. In practice, many providers do not send ruf reports to protect privacy, so rely mainly on rua. And since rua reports come as raw XML that is hard to read by hand, it is a good idea to use a DMARC aggregation and analysis service that turns them into understandable dashboards.
The correct setup order and a gradual tightening strategy
The costliest mistake is jumping straight to p=reject before making sure that all your legitimate email sources pass authentication: your invoices and marketing messages get rejected and your email disappears without warning. The safe path is gradual and methodical. Here is the recommended order:
- Set up SPF first: gather all the servers and services that send in your name (your mail server, the marketing tool, the billing system, the helpdesk) and write a single SPF record covering them all, with a temporary
~allqualifier. - Enable DKIM for every sending service: for each service, create a key pair and publish the public key under its own selector, and make sure the service actually signs its messages.
- Publish DMARC with a
p=nonepolicy: start by monitoring only, withruato collect reports, without any effect on delivery. - Analyze the reports for weeks: keep watching until you see that all your legitimate sources pass alignment, and discover what you missed.
- Tighten gradually: move to
quarantinewith a lowpct, then raise the percentage, then move toreject.
The pct tag is your golden tool for gradual tightening: instead of applying the policy to 100% of your email at once, apply it to a small percentage and watch the effect. The following table suggests realistic stages for moving from monitoring to full protection:
| Stage | DMARC record | Goal |
|---|---|---|
| 1 — Monitoring | p=none; rua=mailto:... | Collect data with no impact |
| 2 — Partial quarantine | p=quarantine; pct=25 | Test the impact on a quarter of the email |
| 3 — Full quarantine | p=quarantine; pct=100 | Quarantine everything that fails |
| 4 — Partial rejection | p=reject; pct=50 | Start rejecting gradually |
| 5 — Full protection | p=reject; pct=100 | Maximum protection |
Do not rush between stages. At each stage, wait until the reports settle and show no legitimate source failing. If you have subdomains, use the sp tag to apply a separate policy to them. The general rule: reaching p=reject can take anywhere from weeks to months depending on how complex your setup is, and that is normal and healthy.
Common mistakes and how to fix them
The same mistakes tend to recur when setting up these records. Knowing them in advance saves you hours of troubleshooting. The following table brings together the most common ones, with the direct fix for each:
| Mistake | Symptom | Fix |
|---|---|---|
| Multiple SPF records | SPF fails randomly (permerror) | Merge all SPF mechanisms into a single TXT record only |
| Exceeding the 10-lookup limit | permerror and dropped messages | Reduce include, replace some with ip4, or use flattening |
Using +all | Your domain can be spoofed | Change it immediately to ~all, then -all |
| Forgetting a sending service | Legitimate email fails authentication | Add the service to SPF and enable DKIM for it |
Jumping to p=reject | Legitimate email is rejected | Go back to p=none, then tighten gradually |
| A truncated DKIM key | DKIM always fails | Copy the full public key without truncation |
| SPF under the wrong name | The record is not read | Put SPF on the root @, not on a subname |
The From domain is not aligned | DMARC fails even though SPF/DKIM pass | Unify the Return-Path/d= domain with From |
The multiple SPF records mistake deserves a special explanation, because it is the most common. The specification requires only one SPF record per domain. If you added Google and created a record, then added a marketing tool and created a second record, you now have two records starting with v=spf1, which is invalid, so evaluation fails. The fix is to merge them into a single line:
example.com. IN TXT "v=spf1 include:_spf.google.com include:servers.mcsv.net ~all"Another frequent mistake is confusing the qualifiers and expecting ~all to provide strict protection. It does not: it is merely "lenient." To understand how these settings relate to getting your email into the inbox in general, see the guide why your email goes to spam, which covers the other factors beyond authentication, such as reputation and content.
Verification and testing
Never trust that a record works just because you saved it in your DNS panel. Remember that any DNS change needs time to propagate according to the TTL, and your panel may show something different from what has actually propagated. Practical verification is done from two sides: reading the published record directly from DNS, then sending a test message and checking the authentication result in it.
Checking from the command line
The fastest way to read the published record is the dig tool. To read the SPF record:
dig TXT example.com +shortTo read the DKIM record (replacing mail with your actual selector):
dig TXT mail._domainkey.example.com +shortAnd to read the DMARC record:
dig TXT _dmarc.example.com +shortOn Windows, the equivalent is nslookup:
nslookup -type=TXT _dmarc.example.comIf the command does not return the record you expect, then either it has not propagated yet, it is under the wrong name, or the DNS panel added unexpected quotes or spaces. Always compare the output of dig with what you wrote, character for character.
Testing and reporting tools
Alongside the command line, there are tools and services that test the complete setup and read the reports for you. The following table summarizes their types:
| Tool type | What it does |
|---|---|
| Web-based SPF/DKIM/DMARC checker | Validates record syntax and the lookup count |
| "Send a message" test | You send a message to a test address and it shows the full authentication result |
| DMARC analysis dashboards | Turn XML rua reports into understandable charts |
| Inspecting message headers | Manually, via "Show original" in your email client |
The simplest and most reliable way to confirm that authentication works end to end: send a message from your domain to your Gmail account, open it, choose "Show original," and you will find a clear summary saying SPF: PASS, DKIM: PASS and DMARC: PASS. If you see PASS for all three with proper alignment, you are on the right track. If you see FAIL or SOFTFAIL, read the details to find out which layer needs fixing.
SPF, DKIM and DMARC at a glance
After all this detail, it helps to bring the big picture together in a single table that shows how the three layers complement each other and why you need them together rather than individually:
| Aspect | SPF | DKIM | DMARC |
|---|---|---|---|
| Answers | Who is allowed to send? | Are the signature and content intact? | What do I do on failure? |
| Checks | The sending IP address | A digital signature | Alignment + policy |
| Domain checked | Return-Path | The d= tag | The visible From |
| Survives forwarding? | Usually no | Usually yes | Depends on the two layers |
| Technology | An allowlist | Public/private key cryptography | Alignment + reports |
| Protects the visible address? | Not on its own | Not on its own | Yes |
The essential takeaway: none of them can be skipped. SPF alone does not protect the visible address, DKIM alone does not dictate a policy, and DMARC without SPF or DKIM has nothing to align with. Together, the three build a complete fence around your domain's identity in email, protecting your reputation and ensuring your messages get delivered. And if your email or hosting provider offers a control panel that generates the correct values for you, setting up these records becomes simpler.
Frequently asked questions
Do I need all three records, or is one enough?
You need them together. SPF defines the allowed servers but checks the Return-Path, not the visible address; DKIM signs the content but does not dictate a policy on failure; and DMARC ties the two together through alignment, protects the visible address and sends reports. Relying on just one leaves a gap. The big mailbox providers today (Gmail, Yahoo) effectively require all three from bulk senders.
What is the difference between ~all and -all in SPF?
Both apply to addresses not included in your list. ~all (SoftFail) means "accept it but mark it as suspicious," which is suitable during setup so legitimate messages are not rejected if you forgot a server. -all (Fail) means "reject it clearly"; it is the strongest and is used once DMARC reports confirm that your list is complete. Start with ~all and move to -all later.
Why did SPF fail after I added a new service?
Most likely you exceeded the 10 DNS lookup limit, or you created a second SPF record by mistake. Every include counts toward the limit, and each service may pull in additional internal records. The fix: merge everything into a single TXT record, reduce the number of include entries, replace some of them with explicit ip4 addresses, or use SPF flattening.
Is alignment necessary for DMARC to pass?
Yes, it is the core of DMARC. It is not enough for SPF or DKIM to pass; the domain that passed must be aligned with the visible From domain. DMARC passes if at least one alignment holds. The value r (Relaxed) accepts subdomains, while s (Strict) requires an exact match. Alignment is what stops spoofing of your domain where SPF and DKIM alone fall short.
When should I move to p=reject?
Only after DMARC reports have shown over several weeks that all your legitimate email sources pass alignment. Start with p=none to monitor, then quarantine with a low pct that you raise gradually, then partial reject, then full. Rushing will drop your legitimate email. Getting to reject can take weeks to months, and that is normal.
Why does my email fail after it is forwarded? Because SPF usually fails on forwarding: the forwarding server is not on your allowlist. Fortunately, DKIM usually survives forwarding, because its signature is tied to the content, not to an IP address. That is exactly why having DKIM alongside SPF matters: when SPF fails after forwarding, alignment through DKIM rescues the DMARC pass.
Does DMARC protect me from every kind of phishing?
It protects you from exact-domain spoofing, that is, the use of your domain in the From field. But it does not stop "lookalike domains" (such as examp1e.com instead of example.com), because they are other domains you do not own. So combine DMARC with user awareness, monitoring of lookalike domains and registering them proactively when possible.
How long do changes to these records take to show up?
They are subject to normal DNS propagation according to the TTL, usually from minutes to a few hours. Do not judge the result immediately after saving; check with dig or nslookup that the published record matches what you wrote. DMARC aggregate reports arrive roughly daily, so give yourself a few days before assessing the full picture.
Sources
Frequently asked questions
Do I need all three records, or is one enough?
You need them together. SPF defines the allowed servers but checks the Return-Path, not the visible address; DKIM signs the content but does not dictate a policy on failure; and DMARC ties the two together through alignment, protects the visible address and sends reports. Relying on just one leaves a gap. The big mailbox providers today (Gmail, Yahoo) effectively require all three from bulk senders.
What is the difference between ~all and -all in SPF?
Both apply to addresses not included in your list. ~all (SoftFail) means "accept it but mark it as suspicious," which is suitable during setup so legitimate messages are not rejected if you forgot a server. -all (Fail) means "reject it clearly"; it is the strongest and is used once DMARC reports confirm that your list is complete. Start with ~all and move to -all later.
Why did SPF fail after I added a new service?
Most likely you exceeded the 10 DNS lookup limit, or you created a second SPF record by mistake. Every include counts toward the limit, and each service may pull in additional internal records. The fix: merge everything into a single TXT record, reduce the number of includes, replace some of them with explicit ip4 addresses, or use SPF flattening.
Is alignment necessary for DMARC to pass?
Yes, it is the core of DMARC. It is not enough for SPF or DKIM to pass; the domain that passed must be aligned with the visible From domain. DMARC passes if at least one alignment holds. The value r (Relaxed) accepts subdomains, while s (Strict) requires an exact match. Alignment is what stops spoofing of your domain where SPF and DKIM alone fall short.
When should I move to p=reject?
Only after DMARC reports have shown over several weeks that all your legitimate email sources pass alignment. Start with p=none to monitor, then quarantine with a low pct that you raise gradually, then partial reject, then full reject. Rushing will drop your legitimate email. Getting to reject can take weeks to months, and that is normal.
Why does my email fail after it is forwarded?
Because SPF usually fails on forwarding: the forwarding server is not on your allowlist. Fortunately, DKIM usually survives forwarding, because its signature is tied to the content, not to an IP address. That is exactly why having DKIM alongside SPF matters: when SPF fails after forwarding, alignment through DKIM rescues the DMARC pass.
Does DMARC protect me from every kind of phishing?
It protects you from exact-domain spoofing, that is, the use of your domain in the From field. But it does not stop "lookalike domains" (such as examp1e.com instead of example.com), because they are other domains you do not own. So combine DMARC with user awareness, monitoring of lookalike domains and registering them proactively when possible.
How long do changes to these records take to show up?
They are subject to normal DNS propagation according to the TTL, usually from minutes to a few hours. Do not judge the result immediately after saving; check with dig or nslookup that the published record matches what you wrote. DMARC aggregate reports arrive roughly daily, so give yourself a few days before assessing the full picture.