Correct DNS configuration for email is the foundation of email deliverability. MX records specify where incoming email should be delivered; SPF, DKIM, and DMARC verify the sender's authenticity. DNS errors can cause delivery failures or messages to land in spam. This guide covers each record with examples and common mistakes.
You can check your current configuration with the email checker and DNS Lookup. Also see the SPF, DKIM, and DMARC guide and email deliverability.
MX records (Mail Exchange)
Purpose
MX (Mail Exchange) records specify the servers that accept email for a domain. When sending an email to user@example.com, the sender performs an MX DNS lookup for example.com and receives a list of servers with priorities.
Record format
example.com. IN MX 10 mail.example.com.| Field | Value | Description |
|---|---|---|
| Name | example.com | Domain (often left blank or set to @) |
| Type | MX | Record type |
| Priority | 10 | Lower means higher priority (0–65535) |
| Value | mail.example.com | Mail server host |
Multiple MX servers
For redundancy, configure multiple records with different priorities:
example.com. IN MX 10 mail1.example.com.
example.com. IN MX 20 mail2.example.com.mail1 is used first; if it is unavailable, mail2 is used.
A record for the mail server
An MX record points to a hostname. An A record (or AAAA record for IPv6) is required:
mail.example.com. IN A 192.0.2.10Examples for popular providers
Google Workspace:
example.com. IN MX 5 gmail-smtp-in.l.google.com.
example.com. IN MX 10 alt1.gmail-smtp-in.l.google.com.
example.com. IN MX 20 alt2.gmail-smtp-in.l.google.com.
example.com. IN MX 30 alt3.gmail-smtp-in.l.google.com.
example.com. IN MX 40 alt4.gmail-smtp-in.l.google.com.Yandex 360:
example.com. IN MX 10 mx.yandex.ru.Mail.ru for Business:
example.com. IN MX 10 mx1.mail.ru.
example.com. IN MX 20 mx2.mail.ru.Microsoft 365:
example.com. IN MX 0 example-com.mail.protection.outlook.com.Checking MX records
dig MX example.com +short
# или
nslookup -type=MX example.comIn DNS Lookup — enter the domain and select the MX record type.
SPF (Sender Policy Framework)
Purpose
SPF specifies which servers can send email on behalf of a domain. The receiving server checks the sender's IP against the SPF record. The record is a TXT record with a specific format.
Basic syntax
example.com. IN TXT "v=spf1 [механизмы] [модификатор]"SPF mechanisms
| Mechanism | Description | Example |
|---|---|---|
ip4 | IPv4 address or subnet | ip4:192.0.2.1 or ip4:192.0.2.0/24 |
ip6 | IPv6 | ip6:2001:db8::/32 |
a | Domain's A record | a or a:mail.example.com |
mx | Domain's MX records | mx |
include | Include another domain's SPF record | include:_spf.google.com |
all | All others | -all (deny) |
Default modifiers
-all— hard fail for unauthorized senders. Recommended for production.~all— softfail. For testing.?all— neutral. Not recommended.+all— allow all. Do not use.
Limitations
- One SPF record per domain
- A maximum of 10
includemechanisms (DNS limit) - Record length: up to 255 characters (multiple TXT strings are concatenated)
- A maximum of 10 DNS lookups during validation (each
includeis a lookup)
SPF examples
Own server only:
v=spf1 ip4:192.0.2.10 -allGoogle Workspace:
v=spf1 include:_spf.google.com -allYandex:
v=spf1 include:_spf.yandex.net -allMail.ru:
v=spf1 include:mail.ru -allMultiple providers (Google + SendGrid):
v=spf1 include:_spf.google.com include:sendgrid.net -allCommon SPF mistakes
- Multiple SPF records — only one is allowed. Combine the mechanisms in a single record.
- Missing
-all— without a modifier, the record is incomplete. Use-allin production. - Overly broad
+all— allows everyone, making it pointless. - Incorrect include — check the exact domain name with the provider (for example,
_spf.google.com, notspf.google.com).
DKIM (DomainKeys Identified Mail)
Purpose
DKIM adds a cryptographic signature to an email. The receiving server verifies the signature using a public key in DNS. It guarantees integrity and authenticity.
How it works
- The sender generates a key pair (private and public)
- The private key is stored on the mail server
- The public key is published in DNS
- The email is signed with the private key when sent
- The recipient extracts the selector from the header, requests the key from DNS, and verifies the signature
DNS record format
selector._domainkey.example.com. IN TXT "v=DKIM1; k=rsa; p=PUBLIC_KEY_BASE64"selector is an arbitrary name (for example, default, mail, s1). A domain can have multiple selectors (for key rotation).
Generating keys
OpenSSL:
# Генерация приватного ключа (2048 бит)
openssl genrsa -out dkim_private.pem 2048
# Извлечение публичного ключа в формате для DNS
openssl rsa -in dkim_private.pem -pubout -outform DER | base64 -w 0The output is a long Base64 string. Add it to the record:
default._domainkey.example.com. IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA..."Configuration in mail systems
Postfix + OpenDKIM:
# /etc/opendkim.conf
Domain example.com
Selector default
KeyFile /etc/opendkim/keys/default.privateExim: Use the dkim or dkimsign plugin. Configuration depends on the build.
Third-party providers (SendGrid, Mailgun, etc.): The provider supplies a ready-to-use DNS record. Usually, in the dashboard: “Authenticate domain” → copy the TXT record.
Checking DKIM
Send a test email to your own mailbox. Find DKIM-Signature in the headers. The Email Checker can show the DKIM status.
DMARC (Domain-based Message Authentication, Reporting and Conformance)
Purpose
DMARC combines SPF and DKIM, sets a policy for failures to align, and lets you receive reports on validation results.
Record format
_dmarc.example.com. IN TXT "v=DMARC1; p=[policy]; rua=mailto:dmarc@example.com"Main tags
| Tag | Description | Values |
|---|---|---|
p | Policy for the domain | none, quarantine, reject |
sp | Policy for subdomains | Same as p |
rua | Email address for aggregate reports | mailto:dmarc@example.com |
ruf | Email address for failure reports | mailto:forensics@example.com |
pct | Percentage of emails to which the policy applies | 0–100 (default: 100) |
adkim | DKIM alignment strictness | r (relaxed) or s (strict) |
aspf | SPF alignment strictness | r or s |
Policies
- p=none — monitoring; emails are not blocked. Use this to start.
- p=quarantine — emails that fail validation are quarantined (sent to spam).
- p=reject — emails that fail validation are rejected. Maximum protection.
Gradual deployment
Stage 1 (testing):
v=DMARC1; p=none; rua=mailto:dmarc@example.comCollect reports for 1–2 weeks. Analyze whether your emails pass SPF and DKIM.
Stage 2 (quarantine):
v=DMARC1; p=quarantine; pct=10; rua=mailto:dmarc@example.com10% of emails that fail validation are quarantined. Gradually increase pct to 100.
Stage 3 (strict policy):
v=DMARC1; p=reject; rua=mailto:dmarc@example.com; ruf=mailto:forensics@example.comProcessing reports
Reports arrive in XML. Use analysis services such as Postmark, Valimail, and dmarcian, or parse them yourself to understand email sources and validation results.
Complete configuration example
Domain example.com, email through Google Workspace, newsletters through SendGrid.
MX:
example.com. IN MX 5 gmail-smtp-in.l.google.com.
example.com. IN MX 10 alt1.gmail-smtp-in.l.google.com.SPF (Google + SendGrid):
example.com. IN TXT "v=spf1 include:_spf.google.com include:sendgrid.net -all"DKIM for SendGrid (selector s1, key from the provider):
s1._domainkey.example.com. IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA..."DMARC:
_dmarc.example.com. IN TXT "v=DMARC1; p=quarantine; rua=mailto:dmarc-reports@example.com"Checking the configuration
Manual DNS check
# MX
dig MX example.com +short
# SPF (TXT)
dig TXT example.com +short
# DKIM (подставьте свой селектор)
dig TXT default._domainkey.example.com +short
# DMARC
dig TXT _dmarc.example.com +shortOnline tools
- Email Checker — comprehensive SPF, DKIM, and DMARC checks
- DNS Lookup — view any DNS records
Sending a test email
Services such as mail-tester.com and glockapps.com let you send an email to a specified address and get a score and details of SPF/DKIM/DMARC checks.
DNS propagation and delays
DNS changes do not propagate instantly. TTL (Time To Live) determines how long records are cached. Typical values: 300 (5 min), 3600 (1 hour), 86400 (24 hours).
When configuring DNS for the first time, use a low TTL (300) so you can roll back more quickly if there is an error. Increase it once things are stable.
Additional email records
PTR (reverse DNS record)
For outbound servers, configure a PTR (reverse DNS) record: the IP should resolve to a hostname that matches the name in HELO/EHLO. Many providers check PTR and reject emails when it does not match. Configure it with your hosting provider, not in a regular DNS zone.
BIMI (Brand Indicators for Message Identification)
An optional record for displaying a logo in supported clients (Gmail, Yahoo). Requires DMARC with a p=quarantine or p=reject policy and a verified VMC certificate. It is still rarely used.
MTA-STS (Mail Transfer Agent Strict Transport Security)
A policy that enforces TLS for email delivery. Create a _mta-sts.example.com record and a file at https://mta-sts.example.com/.well-known/mta-sts.txt. Protects against downgrade attacks during transmission between servers.
TLS Reporting
Reports TLS issues during email delivery. A _smtp._tls.example.com record with rua=mailto:tlsreports@example.com. Helps identify attacks and encryption failures.
Migrating email providers
When changing providers (for example, from your own server to Google Workspace):
- Prepare the new records — MX, SPF, and DKIM from the new provider
- Lower the TTL 24–48 hours before switching
- Update MX — email will start arriving at the new server
- Update SPF — add the new provider's include and remove old IPs
- Configure DKIM — new selector and key
- DMARC — keep p=none for 1–2 weeks for monitoring
- Check with Email Checker
Running two providers in parallel: you can temporarily include both in SPF, then remove the old one.
DKIM key rotation
Periodic DKIM key changes improve security. Process:
- Create a new selector (for example,
s2instead ofs1) - Generate a new key pair
- Add a DNS record for
s2._domainkey.example.com - Configure the mail server to sign with selector
s2 - Wait for DNS propagation (TTL)
- Switch sending to
s2 - After 1–2 weeks, delete the old
s1record (for compatibility with emails in transit)
DNS limitations and limits
- SPF: up to 10
includemechanisms, up to 10 DNS lookups during validation. If exceeded, validation stops with softfail. - TXT record: up to 255 characters in one string. Long records are split into multiple quoted strings, which are concatenated when read.
- DKIM: key length of 1024 or 2048 bits. 2048 is recommended for long-term security.
Troubleshooting: common scenarios
Emails are not arriving — check MX: do they point to the correct server, and does the hostname resolve to an IP? Check the firewall and port 25.
Emails are going to spam — check SPF (does the sender IP match?), DKIM (is the signature valid?), and DMARC (policy and reports). Use Email Checker.
SPF fail — make sure the sending server's IP is included in an include mechanism or explicitly listed. Check that there are no multiple SPF records.
DKIM fail — the selector in the email header must match the selector in DNS. The key in DNS must be complete, with no line breaks (if split across strings, they are concatenated without spaces).
Conclusion
DNS configuration for email — MX, SPF, DKIM, and DMARC — is the minimum required for stable deliverability. Follow the examples above, check the configuration with Email Checker and DNS Lookup, and your emails will pass receiving servers' checks. More resources: SPF, DKIM, and DMARC and email deliverability.