Every day, mail servers around the world process billions of emails, and a significant proportion of them are fraudulent. An attacker sends an email claiming to be from your bank, your employer, or your domain—and the recipient sees a familiar address in the “From” field. The SMTP protocol, developed in 1982, did not provide any sender verification. Any server could send an email with any return address—and for many years, this was the norm.
Three technologies—SPF, DKIM, and DMARC—were created to close this gap. Together, they form an email authentication system that allows a receiving server to determine whether an email was actually sent from an authorized server and whether it was altered in transit. If you administer a mail domain and have not yet configured all three records, this article is for you.
Why email authentication is needed
Spoofing and phishing
Email spoofing is the forgery of a sender's address. An attacker sends an email from ceo@yourcompany.ru to an accounting employee, asking them to urgently transfer money. The email looks legitimate because SMTP does not check whether the sending server is authorized to use that domain.
Phishing works on a similar principle, but targets customers: an email appears to be from support@yourbank.ru and contains a link to a fake login page. According to the Verizon DBIR report, phishing remains an initial access vector in 36% of successful cyberattacks. In most cases, the attack starts with a forged email address.
Email deliverability
Even if you are not concerned about fraudsters, email authentication directly affects the deliverability of your own emails. Google, Yahoo, Mail.ru, and Yandex state publicly that domains without valid SPF, DKIM, and DMARC records receive lower trust ratings. Your marketing campaigns, transactional notifications, and even ordinary business correspondence may end up in the “Spam” folder or be rejected entirely.
Since February 2024, Google and Yahoo have required bulk senders (more than 5000 emails per day) to have SPF and DKIM, a valid DMARC record, and one-click unsubscribe functionality. Senders that do not meet these requirements have their emails rejected.
Domain reputation
Every email provider maintains a domain reputation score. This reputation takes years to build and hours to destroy. A single phishing campaign sent from your domain—even if you had nothing to do with it—can be enough to get you on blocklists. Recovery takes weeks and requires contacting each provider separately. Properly configured email authentication is insurance against this scenario.
SPF — Sender Policy Framework
How SPF works
SPF lets a domain owner specify in a DNS record which servers are authorized to send email on behalf of that domain. When a receiving server gets an email with the address user@example.com, it queries the domain example.com in DNS and retrieves its SPF record. It then checks the sending server's IP address against the list of authorized addresses and makes a decision.
Technically, an SPF record is a TXT record in DNS. The receiving server checks the address in the email envelope (MAIL FROM), not the From: header that the user sees. This is an important detail that we will return to when discussing DMARC.
SPF record syntax
Every SPF record starts with v=spf1 and ends with a default mechanism. Authorized sources are listed between them:
v=spf1 [механизмы] [модификатор_по_умолчанию]Main mechanisms:
| Mechanism | Description | Example |
|---|---|---|
ip4 | Authorize a specific IPv4 address or subnet | ip4:192.168.1.1 or ip4:10.0.0.0/24 |
ip6 | Authorize an IPv6 address or subnet | ip6:2001:db8::/32 |
a | Authorize IP addresses from the domain's A record | a:mail.example.com |
mx | Authorize IP addresses from the domain's MX records | mx |
include | Include another domain's SPF record | include:_spf.google.com |
redirect | Redirect the check to another domain | redirect=_spf.example.com |
Default modifiers determine what to do with servers that are not on the list:
| Modifier | Meaning | When to use |
|---|---|---|
+all | Allow all | Never. A pointless record |
~all | Soft fail | During testing |
-all | Hard fail | In production |
?all | Neutral | Rarely; equivalent to having no record |
SPF record examples for different providers
Google Workspace:
v=spf1 include:_spf.google.com -allYandex 360 for business:
v=spf1 include:_spf.yandex.net -allMail.ru for business:
v=spf1 include:_spf.mail.ru -allCombined record — Google Workspace + your own mail server + the SendPulse mailing service:
v=spf1 include:_spf.google.com ip4:185.100.50.25 include:spf.sendpulse.com -allA domain that does not send email at all:
v=spf1 -allThis record is especially important for parked domains and subdomains that do not use email. Without it, attackers can send emails from those domains with impunity.
The limit of 10 DNS queries
SPF has a strict limit: processing a record allows no more than 10 DNS queries. Each of the mechanisms include, a, mx, and redirect generates at least one query. And include can refer to records that contain their own include mechanisms, all of which count toward the total.
Let's look at an example. The record include:_spf.google.com makes 1 queries. But _spf.google.com contains another 3 includes, making a total of 4 queries for Google alone. Add include:_spf.mail.ru (another 2-3 queries) and a mailing service (another 1-2), and you are already close to the limit.
Exceeding the limit results in a permerror error, and the entire SPF check is considered to have failed. Emails may go to spam or be rejected.
Ways to stay within the limit:
- Replace
includewith specificip4/ip6addresses wherever possible. Theip4andip6mechanisms do not generate DNS queries. - Use the
redirectmechanism instead of multipleincludemechanisms, moving all the logic to a separate subdomain. - Services such as SPF flattening automatically expand
includeinto lists of IP addresses, but require regular updates.
Example of an optimized record using a subdomain:
; Основная запись
v=spf1 redirect=_spf.example.com
; _spf.example.com
v=spf1 ip4:142.250.0.0/16 ip4:172.217.0.0/16 ip4:185.100.50.25 include:spf.sendpulse.com -allDKIM — DomainKeys Identified Mail
How DKIM works
While SPF checks which server sent an email, DKIM checks the integrity of the email itself. The mechanism is based on asymmetric cryptography: the sending server signs the email headers and body with a private key, and the receiving server verifies the signature using the public key published in DNS.
When an email is sent, the mail server calculates a hash of the headers and body, encrypts it with the private key, and adds the signature to the DKIM-Signature header. The receiving server extracts the domain and selector from the header, retrieves the public key from DNS, decrypts the signature, and compares the hashes. If they match, the email is authentic and was not altered in transit.
DKIM DNS record
The public key is published in a DNS TXT record at [селектор]._domainkey.[домен]. A selector is an arbitrary label that lets you use multiple keys at the same time.
Example DNS record:
; Имя записи: google._domainkey.example.com
; Тип: TXT
; Значение:
v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3QEKyU1fSm...публичный_ключ...QABParameter details:
| Parameter | Description |
|---|---|
v=DKIM1 | Protocol version |
k=rsa | Key algorithm (rsa or ed25519) |
p=... | Public key in Base64 format |
t=s | Strict mode (optional; disallows subdomains) |
t=y | Testing mode (optional) |
Configuring DKIM for different providers
Google Workspace:
Google generates a key in the Admin Console (Admin Console → Apps → Google Workspace → Gmail → Authenticate email). The default selector is google and the key is 2048 bits long. Google provides the TXT record value; you need to create the record in DNS.
; Имя: google._domainkey.example.com
; Тип: TXT
v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...Important: a 2048-bit key does not fit on a single line in a DNS TXT record (the limit is 255 characters per line). Most DNS providers automatically split long records, but some require you to split them manually using quotation marks:
v=DKIM1; k=rsa; p="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA..." "...продолжение_ключа..."Yandex 360:
Yandex automatically enables DKIM for domains connected to Yandex 360. The selector is mail. The record is created automatically if DNS is managed by Yandex. For external DNS, get the value from the admin panel.
; Имя: mail._domainkey.example.com
; Тип: TXT
v=DKIM1; k=rsa; t=s; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNAD...Your own mail server (Postfix):
Postfix uses OpenDKIM. Generate keys with:
opendkim-genkey -s mail -d example.com -b 2048The command creates two files: mail.private (private key) and mail.txt (DNS record). Place the private key in /etc/opendkim/keys/example.com/mail.private, and publish the contents of mail.txt in DNS.
OpenDKIM configuration (/etc/opendkim.conf):
Domain example.com
KeyFile /etc/opendkim/keys/example.com/mail.private
Selector mail
Socket inet:8891@localhost
Canonicalization relaxed/simpleKey rotation
DKIM keys do not have a built-in expiration date, but it is recommended that you change them every 6–12 months. The reason is that if the private key is compromised, an attacker can sign emails on behalf of your domain, and DKIM checks will pass.
Rotation procedure with no downtime:
- Generate a new key pair with a new selector (for example,
mail202603). - Publish the new public key in DNS. Wait for it to propagate (the old record's TTL).
- Switch the mail server to use the new private key and selector.
- Keep the old DNS record for a period equal to the maximum delivery time for delayed emails (48–72 hours).
- Delete the old DNS record.
Using dates in selector names simplifies management:
; Текущий ключ
mail202603._domainkey.example.com TXT "v=DKIM1; k=rsa; p=..."
; Следующий ключ (подготовлен заранее, но ещё не используется сервером)
mail202609._domainkey.example.com TXT "v=DKIM1; k=rsa; p=..."RSA vs. Ed25519
Traditionally, DKIM uses RSA keys that are 1024 or 2048 bits long. The Ed25519 algorithm is a more modern alternative with compact keys (44 characters in Base64) and comparable cryptographic strength:
v=DKIM1; k=ed25519; p=11qYAYKxCrfVS/7TyWQHOg7hcvPapiMlrwIaaPcHURo=Ed25519 is not yet supported by all providers. A reasonable strategy is to publish both keys with different selectors and configure the server to sign with both.
DMARC — Domain-based Message Authentication
What DMARC does
SPF and DKIM each solve specific problems, but neither gives the domain owner control over what happens when a check fails. SPF passes but DKIM does not? Or the other way around? What should happen to such an email—accept it, reject it, or send it to spam? Each email provider handled this differently.
DMARC standardizes this behavior: the domain owner publishes a policy that explicitly states what to do with emails that fail authentication. DMARC also addresses the problem of alignment: it checks that the domain in the From: header (which the user sees) matches the domain that passed the SPF or DKIM check.
Without DMARC, an attacker could send an email with MAIL FROM: hacker@evil.com (SPF would pass for evil.com) and the From: ceo@yourcompany.ru header (which the recipient would see). DMARC prevents this.
DMARC record syntax
A DMARC record is a DNS TXT record named _dmarc.[домен]:
; Имя: _dmarc.example.com
; Тип: TXT
v=DMARC1; p=reject; rua=mailto:dmarc-reports@example.com; ruf=mailto:dmarc-forensic@example.com; adkim=s; aspf=s; pct=100Parameters:
| Parameter | Values | Description |
|---|---|---|
v | DMARC1 | Version (required) |
p | none, quarantine, reject | Policy for the primary domain (required) |
sp | none, quarantine, reject | Policy for subdomains (optional, inherits p) |
rua | mailto:адрес | Where to send aggregate reports |
ruf | mailto:адрес | Where to send forensic reports |
adkim | r (relaxed), s (strict) | Alignment for DKIM |
aspf | r (relaxed), s (strict) | Alignment for SPF |
pct | 1–100 | Percentage of emails to which the policy applies |
fo | 0, 1, d, s | Conditions for generating forensic reports |
DMARC policies
p=none — monitoring mode. Emails are delivered as usual, but you receive reports. This is the starting point for any deployment.
v=DMARC1; p=none; rua=mailto:dmarc@example.comp=quarantine — suspicious emails are sent to spam. The recipient can still see them, but they won't reach the inbox.
v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com; pct=100p=reject — the recipient's mail server rejects the email at the SMTP level. It is not delivered at all—not to the inbox or to spam. Maximum protection.
v=DMARC1; p=reject; rua=mailto:dmarc@example.com; ruf=mailto:dmarc-forensic@example.com; adkim=s; aspf=sReports: rua and ruf
One of DMARC's most valuable features is reporting. Without reports, you are working blind, with no way to know who is sending email on behalf of your domain.
Aggregate reports (rua) arrive in XML format once a day from each major provider. They contain statistics: how many emails passed SPF/DKIM, how many failed, and which IP addresses sent them. The volume can be significant—for a domain with average email traffic, expect dozens of reports a day.
Forensic reports (ruf) contain data about specific emails that failed authentication. They are useful for investigating incidents, but not all providers send them (Google, for example, does not send ruf). In addition, forensic reports may contain recipients' personal data, raising GDPR concerns.
Use specialized services or open-source solutions such as parsedmarc to analyze reports. Reading XML files manually is impractical for any noticeable volume of email.
Gradual DMARC deployment
Moving straight to p=reject is a sure way to block legitimate email. Mailing services, CRM systems, ticketing systems, monitoring—everything that sends email on behalf of your domain must be accounted for in SPF and signed with DKIM. DMARC should be deployed gradually.
Stage 1: Audit (2–4 weeks)
v=DMARC1; p=none; rua=mailto:dmarc@example.comCollect reports and analyze email sources. Compile a complete list of servers and services that send email on behalf of your domain.
Stage 2: Soft quarantine (2–4 weeks)
v=DMARC1; p=quarantine; pct=10; rua=mailto:dmarc@example.comApply quarantine to 10% of emails. Monitor reports and feedback from recipients. If there are no problems, increase pct to 25%, 50%, 100%.
Stage 3: Quarantine 100% (2–4 weeks)
v=DMARC1; p=quarantine; pct=100; rua=mailto:dmarc@example.comAll unauthenticated emails go to spam. By this stage, all legitimate sources should be configured correctly.
Stage 4: Reject
v=DMARC1; p=reject; rua=mailto:dmarc@example.com; ruf=mailto:dmarc-forensic@example.comThe final policy. Spoofed emails are rejected entirely. Continue monitoring reports—new services added by the company will require SPF/DKIM updates.
Setup process: step-by-step plan
Below is a sequence of steps for a domain where email authentication is being configured from scratch.
Step 1. Inventory email flows
Before changing DNS, make a list of everything that sends email on behalf of your domain:
- Corporate email (Google Workspace, Yandex 360, Exchange)
- Transactional emails from your application (your own server, SES, SendGrid)
- Marketing campaigns (Unisender, SendPulse, Mailchimp)
- CRM systems (Bitrix24, amoCRM)
- Ticketing systems and help desks (Zendesk, OTRS)
- Monitoring and alerting (Zabbix, Grafana)
A missed source means blocked emails after strict policy is enabled.
Step 2. Configure SPF
Create a TXT record that includes all the sources from step 1:
v=spf1 include:_spf.google.com include:amazonses.com ip4:185.100.50.25 -allCheck that the number of DNS queries does not exceed 10. Use DNS Lookup on reChecker to view the domain's current DNS records and validate the configuration.
Step 3. Configure DKIM
Set up DKIM signing for every service that sends email:
- Corporate email—the key is generated in the provider's control panel.
- Mailing services—each service provides its own DKIM key and instructions.
- Your own server—generate a key using OpenDKIM and publish it in DNS.
Each service uses its own selector, so there are no conflicts:
google._domainkey.example.com TXT "v=DKIM1; k=rsa; p=..."
sendpulse._domainkey.example.com TXT "v=DKIM1; k=rsa; p=..."
mail._domainkey.example.com TXT "v=DKIM1; k=rsa; p=..."Step 4. Publish DMARC in monitoring mode
_dmarc.example.com TXT "v=DMARC1; p=none; rua=mailto:dmarc@example.com"Step 5. Analyze reports (2–4 weeks)
Check the aggregate reports. Determine:
- Whether all legitimate sources pass SPF and DKIM.
- Whether there are unknown IP addresses sending email on your behalf.
- The percentage of checks that pass.
Step 6. Tighten the policy
Gradually move from p=none to p=quarantine (starting at pct=10) and then to p=reject. Pause at each stage and analyze the reports.
Step 7. Configure DMARC for subdomains
If your subdomains do not send email, explicitly prohibit it:
_dmarc.example.com TXT "v=DMARC1; p=reject; sp=reject; rua=mailto:dmarc@example.com"The sp=reject parameter applies a strict policy to all subdomains.
Testing and troubleshooting
After configuration, make sure everything is working correctly. A DNS record syntax error or a missed service can lead to lost emails.
Check DNS records
Make sure the records are published and accessible. Use Email Authentication Checker on reChecker—the service will show the domain's current SPF, DKIM, and DMARC records, check their syntax, and identify common configuration errors.
You can also check them from the command line:
# SPF
dig TXT example.com | grep spf
# DKIM (замените селектор)
dig TXT google._domainkey.example.com
# DMARC
dig TXT _dmarc.example.comSend a test email
Send an email to a Gmail or Yandex mailbox, open the full headers, and find the authentication results:
Authentication-Results: mx.google.com;
dkim=pass header.i=@example.com header.s=google header.b=abc12345;
spf=pass (google.com: domain of user@example.com designates 142.250.150.26 as permitted sender) smtp.mailfrom=user@example.com;
dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=example.comAll three checks should show pass. If even one shows fail or softfail, investigate the cause.
Ongoing monitoring
Email authentication is not a one-time setup. New services, IP address changes, and DKIM key rotation all require DNS record updates. Set up regular checks:
- Analyze DMARC reports weekly.
- Check the SPF record monthly to make sure it is up to date.
- Monitor the expiration dates of SSL certificates that affect email TLS encryption—SSL Checker can help with this.
- Check the security headers of your email web interface using Security Headers.
Common mistakes
Over the years, some mistakes have come up with remarkable regularity. Let's look at the most common ones.
1. Multiple SPF records
A domain can have only one SPF TXT record. If you add a second one (for example, by forgetting to combine records when connecting a new service), both records will be considered invalid:
; НЕПРАВИЛЬНО — две отдельные SPF-записи
v=spf1 include:_spf.google.com -all
v=spf1 include:_spf.yandex.net -all
; ПРАВИЛЬНО — одна объединённая запись
v=spf1 include:_spf.google.com include:_spf.yandex.net -all2. Exceeding the DNS query limit
Adding each new service via include brings you closer to the limit of 10 queries. Developers often fail to count nested includes. You added include:spf.protection.outlook.com—it looks like 1 query, but the Outlook SPF record contains another 2 include internally, bringing the total to 3.
Keep track of the total number of queries every time you make a change. If you exceed the limit, optimize the record by using ip4/ip6 instead of include for stable addresses.
3. No DKIM for third-party services
SPF is configured, DMARC is enabled, but a mailing service sends emails without your domain's DKIM signature. The result: SPF may pass (the service's IP is on the list), but DMARC alignment does not work because the domain in MAIL FROM differs from the domain in From. Emails go to spam.
Solution: configure DKIM signing for every third-party service that sends email on your behalf. All major ESPs (email service providers) provide instructions for setting up custom DKIM.
4. Using ~all instead of -all in production
~all (tilde) means softfail—the receiving server should not reject the email, but only mark it as suspicious. Many administrators set ~all “for testing” and forget to switch to -all. Combined with p=none in DMARC, this completely undermines the protection.
5. Forgotten subdomains
You set up perfect authentication for example.com, but forgot about staging.example.com, dev.example.com, and old.example.com. Attackers know this and deliberately look for unprotected subdomains to spoof.
Solution: add sp=reject to the primary domain's DMARC record and create SPF records v=spf1 -all for every subdomain that does not send email.
6. DMARC without rua
DMARC with p=none and no rua is a record that does nothing. It neither protects the domain nor provides data for analysis. If you publish DMARC, always specify an address for reports.
7. Switching to reject too quickly
Enabling p=reject without first auditing through p=none is guaranteed to block some legitimate email. Forwarding is particularly affected: when a recipient has set up forwarding to another mailbox, the email is delivered from the forwarding server's original IP, not yours—so SPF breaks. Without DKIM, the email will also fail DMARC.
How SPF, DKIM, and DMARC work together
The three technologies work as a single system. It is useful to understand how they relate:
Входящее письмо
│
▼
┌─────────────────┐
│ Проверка SPF │ ← IP отправителя в списке?
│ (MAIL FROM) │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Проверка DKIM │ ← Подпись валидна?
│ (заголовок) │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Проверка DMARC │ ← SPF или DKIM прошли
│ (alignment + │ И домен совпадает с From?
│ политика) │
└────────┬────────┘
│
┌────┴────┐
│ pass │ fail
▼ ▼
Доставка Применение политики
(none/quarantine/reject)DMARC passes if at least one of these conditions is met:
- SPF passes AND the domain in MAIL FROM matches the domain in From (SPF alignment).
- DKIM passes AND the signing domain matches the domain in From (DKIM alignment).
That is why both SPF and DKIM are recommended. Even if SPF breaks during forwarding, the DKIM signature remains valid, and the email passes DMARC.
Conclusion
Email authentication is not an optional recommendation; it is a minimum requirement for any domain that sends email. SPF specifies who is authorized to send, DKIM verifies the integrity of the email, and DMARC ties everything together and gives you control over the policy.
Setup takes a few hours, but protects the domain for years. Key principles:
- Start with an audit: compile a complete list of all email flows.
- Configure all three technologies—they are significantly less effective individually.
- Deploy DMARC gradually:
none→quarantine(with an increasingpct) →reject. - Monitor reports on an ongoing basis—the configuration changes over time and requires updates.
- Don't forget subdomains—protect them with separate records or the
sp=rejectparameter.
If you've been putting off email authentication, start today. Every day without SPF, DKIM, and DMARC is a day when someone could send email on behalf of your domain without you even knowing about it.