Proper DNS setup forms the foundation of email deliverability. Let's examine the critical records:
// Example SPF record (TXT)
v=spf1 ip4:192.0.2.0/24 ip6:2001:db8::/64 include:_spf.google.com -all
The reverse DNS (PTR) record should match your mail server's hostname. For a mail server at mail.example.com with IP 203.0.113.5:
// Reverse DNS zone file entry
5.113.0.203.in-addr.arpa. 3600 IN PTR mail.example.com.
Your SMTP server should present itself properly during the initial handshake:
// Proper HELO/EHLO sequence (actual implementation varies by MTA)
220 mail.example.com ESMTP Postfix
EHLO mail.example.com
250-mail.example.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
Modern email authentication protocols significantly improve deliverability:
# DKIM setup example for Postfix
# In /etc/opendkim.conf
Domain example.com
KeyFile /etc/opendkim/keys/example.com.private
Selector default
Canonicalization relaxed/simple
Mode sv
SubDomains no
DMARC record example for monitoring mode:
// DNS TXT record for _dmarc.example.com
v=DMARC1; p=none; rua=mailto:dmarc-reports@example.com; ruf=mailto:dmarc-forensics@example.com
When sending on behalf of another domain (corporate.tld) from branch.tld:
// SPF record for corporate.tld allowing branch.tld's IP
v=spf1 ip4:198.51.100.0/24 include:_spf.branch.tld ~all
// Sender Rewriting Scheme (SRS) implementation example
# In /etc/postsrsd.secret
SRS_DOMAIN=srs.example.com
SRS_SEPARATOR==
SRS_SECRET=your-secret-key
Regularly check your sender reputation:
#!/bin/bash
# Basic sender score check
IP="203.0.113.5"
curl -s "https://www.senderscore.org/lookup.php?lookup=$IP" | grep -A5 "Sender Score"
Implement feedback loops with major ISPs:
// Example of processing FBL reports
POST /fbl-endpoint HTTP/1.1
Host: yourserver.example.com
Content-Type: message/feedback-report
Feedback-Type: abuse
User-Agent: SomeFeedbackLoopAgent
Version: 1
Original-Mail-From: <bounces@example.com>
Original-Rcpt-To: <recipient@example.com>
Received-Date: Thu, 8 Mar 2012 14:00:00 PDT
Source-IP: 192.0.2.1
Authentication-Results: mail.example.com;
spf=pass smtp.mailfrom=bounces@example.com;
dkim=pass header.i=@example.com
Reported-Domain: example.com
Email spam filters use complex algorithms to determine whether an email is legitimate or spam. These filters analyze various aspects of your email infrastructure and content. As developers, we need to implement technical solutions that satisfy these filters while maintaining functionality.
Proper DNS setup is crucial for email deliverability. Here's what you need:
// Example SPF record (TXT record)
v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.123 a mx include:_spf.google.com ~all
// Example DMARC record
v=DMARC1; p=none; rua=mailto:dmarc-reports@yourdomain.com
// Example DKIM record (selector._domainkey.yourdomain.com)
v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC...
Your mail server setup significantly impacts deliverability:
- Ensure your HELO/EHLO matches your server's FQDN
- Configure proper reverse DNS (PTR) records
- Implement STARTTLS for secure connections
- Maintain proper rate limiting to avoid looking like a spammer
When sending emails on behalf of other domains, you need proper authorization:
// Example of setting From header in PHP
$headers = "From: user@corporate.com\r\n";
$headers .= "Sender: user@yourdomain.com\r\n";
$headers .= "Reply-To: user@corporate.com\r\n";
Even with perfect technical setup, your email content matters:
- Avoid spam trigger words ("free", "guarantee", etc.)
- Maintain a good text-to-HTML ratio
- Include proper unsubscribe mechanisms
- Keep your sending reputation clean
Implement these tools to monitor your email deliverability:
# Python script to check SPF record
import dns.resolver
def check_spf(domain):
try:
answers = dns.resolver.resolve(domain, 'TXT')
for rdata in answers:
if 'v=spf1' in str(rdata):
return str(rdata)
except:
return "No SPF record found"
Regularly test your emails using services like Mail-Tester.com or GlockApps to identify potential issues before they affect your deliverability.