Email DNS records—MX, SPF, DKIM, DMARC, and PTR—are the five key settings that control where your email goes and whether receiving servers trust it. MX records route mail to the correct server, while SPF, DKIM, and DMARC authenticate that the mail is genuinely from you, and PTR records provide reverse DNS for IP reputation.
Background: Why Email Needs DNS Records
Email was designed in the 1970s when the internet was small and trusted. Today, spam and phishing are rampant, so receiving servers use DNS records to verify that an email claiming to be from example.com actually came from a server authorized by example.com. Without these records, your emails are more likely to be marked as spam or rejected outright.
DNS (Domain Name System) is the internet's phonebook, translating domain names into IP addresses. Each type of record serves a different purpose in the email delivery chain. When you send an email, the receiving server looks up your domain's DNS records to decide whether to accept, deliver, or quarantine the message.
MX Records: Where to Deliver the Mail
MX (Mail Exchange) records tell other servers which host should receive email addressed to your domain. For example, if your domain is example.com, an MX record might point to mail.example.com with a priority number.
- Priority: Lower numbers are tried first. If you have two MX records (10 and 20), the server at priority 10 is preferred.
- Hostname: Must be a fully qualified domain name (FQDN), not an IP address.
- TTL: Time-to-live, how long other servers cache the record.
Common mistake: pointing MX records to an IP address (e.g., 192.0.2.1) is invalid. Always use a hostname like mx1.example.com.
SPF: Who Is Allowed to Send
SPF (Sender Policy Framework) is a TXT record that lists the IP addresses or hostnames authorized to send email for your domain. When a receiving server gets a message, it checks the envelope sender (the return-path) against your SPF record.
Example SPF record: v=spf1 ip4:192.0.2.1 include:_spf.google.com ~all
v=spf1— version identifierip4:192.0.2.1— allows that specific IPinclude:_spf.google.com— includes Google's SPF record (if using Gmail)~all— soft fail (mark as suspicious but not reject);-allis hard fail (reject)
SPF has limits: it only checks the envelope sender, not the visible "From" header. That's why DKIM is needed.
DKIM: Digital Signature for Authenticity
DKIM (DomainKeys Identified Mail) adds a digital signature to your email headers. The signature is created with a private key held by your sending server, and the public key is published as a TXT record in your DNS. Receiving servers use that public key to verify the signature, proving the email wasn't altered in transit and that it really came from your domain.
DKIM records look like: v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC...
The selector (a subdomain) is part of the DKIM setup. For example, if your selector is s1, the record is at s1._domainkey.example.com. Each email provider gives you a specific selector and public key to publish.
DKIM is more reliable than SPF because it survives forwarding (SPF often breaks when a message is forwarded).
DMARC: Policy and Reporting
DMARC (Domain-based Message Authentication, Reporting, and Conformance) builds on SPF and DKIM. It tells receiving servers what to do if both SPF and DKIM fail: none (do nothing), quarantine (send to spam), or reject (bounce). It also provides a way for you to receive reports about authentication failures.
DMARC record example: v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com
p=— policy: none, quarantine, or rejectrua=— aggregate report email addressruf=— forensic report address (optional)pct=— percentage of messages to apply policy to (e.g.,pct=50)
DMARC alignment requires that the domain in the "From" header matches the domain used in SPF or DKIM. This prevents someone from spoofing your domain while using another domain's SPF/DKIM.
PTR Records: Reverse DNS for IP Reputation
PTR (Pointer) records map an IP address back to a hostname—the opposite of an A record. They are used for reverse DNS (rDNS) lookups. Many receiving servers check that the IP address of the sending server has a PTR record that matches its hostname. If not, the email may be rejected as spam.
PTR records are typically set by your hosting provider or ISP, not by you in your domain's DNS. For example, if your server's IP is 192.0.2.1, the PTR record might be mail.example.com. The PTR hostname should match the HELO/EHLO name your mail server sends.
Best practice: the PTR record should point to a hostname that has a corresponding A record pointing back to the same IP (forward-confirmed reverse DNS, or FCrDNS).
How to Set Up These Records
- Log into your domain registrar or DNS hosting provider.
- Find the DNS management section (often called "DNS Zone Editor").
- For MX: add an MX record with the hostname and priority given by your email provider.
- For SPF: add a TXT record at the root domain with the SPF value from your provider.
- For DKIM: add a TXT record at the selector name (e.g.,
s1._domainkey) with the public key. - For DMARC: add a TXT record at
_dmarcwith your policy. - For PTR: contact your hosting provider or ISP to set the reverse DNS.
After adding records, wait for DNS propagation (can take up to 48 hours, though often faster). Use online tools like MXToolbox or Google Admin Toolbox to verify.
Common Problems and Misconceptions
- SPF too strict: Using
-allwhen you have multiple senders (e.g., third-party services) can cause legitimate emails to fail. Use~alluntil you're sure. - DKIM selector mismatch: If you change email providers, you must update the DKIM record with the new selector and key.
- DMARC policy too aggressive: Starting with
p=rejectwithout monitoring can break legitimate emails. Start withp=none, then move to quarantine, then reject. - PTR missing: Many ISPs reject email from IPs without PTR records. Always set up rDNS.
- Multiple SPF records: You can only have one SPF record per domain. Combine multiple entries into one record.
Comparison: SPF vs. DKIM vs. DMARC
SPF is like a list of approved senders. DKIM is like a wax seal on the letter. DMARC is the policy that says what to do if the seal is broken or the sender isn't on the list. All three work together; none is sufficient alone.
SPF fails when email is forwarded (the original sender's IP is no longer in the envelope). DKIM survives forwarding because the signature remains intact. DMARC requires alignment, so even if SPF passes, the domain in the From header must match the SPF domain.
Safety and Best Practices
- Always use strong DKIM keys (2048-bit RSA is common).
- Monitor DMARC reports before enforcing a reject policy.
- Keep SPF records under 255 characters per string (though multiple strings are allowed).
- Never publish a PTR record that points to a generic hostname like
ip-192-0-2-1.example.net; use a descriptive hostname. - Regularly check your DNS records with free validation tools.
Frequently Asked Questions
Can I have both SPF and DKIM without DMARC?
Yes, but DMARC is recommended because it tells receiving servers how to handle failures. Without DMARC, a server may silently drop or spam-folder your email, and you won't know why.
What is the difference between MX and A records?
An A record maps a hostname to an IP address, while an MX record specifically tells where to route email. MX records can point to a hostname that has its own A record, but they are separate records.
How do I check if my PTR record is correct?
Use a reverse DNS lookup tool, or run nslookup from a command line. The output should show a hostname that matches your mail server's HELO name.
Why is my email going to spam even with all records set?
Other factors include content (spammy words), sending volume, recipient engagement, and IP reputation. DNS records are necessary but not sufficient. Check your IP's blacklist status and consider warming up a new IP.
Do I need a PTR record for every domain I send from?
No, PTR is tied to the IP address, not the domain. If you send from multiple domains using the same server IP, that IP's PTR record should match the server's hostname, not each domain.
Can I use a third-party email service and still set these records?
Yes, in fact most providers require you to set MX, SPF, and DKIM records. They will give you the exact values to add. DMARC is optional but recommended.