Key Takeaways
- Setting up your own SMTP server on a dedicated server gives you full sending control.
- This step-by-step guide walks through Postfix installation, DNS configuration, and testing.
Running your own SMTP server on a dedicated server gives you complete control over email delivery, authentication, and volume. This guide covers Postfix — the most widely deployed SMTP server in the world — from installation to production-ready configuration.
Prerequisites
- A dedicated server with Ubuntu 22.04 or 24.04
- A domain name with DNS management access
- Root or sudo access
- Port 25 open from your hosting provider
Step 1: Set Correct Hostname
hostnamectl set-hostname mail.yourdomain.com
echo "127.0.0.1 mail.yourdomain.com" >> /etc/hosts
Step 2: Install Postfix
apt update && apt install -y postfix mailutils
# During installation, choose "Internet Site"
# System mail name: yourdomain.com
Step 3: Configure Postfix
# /etc/postfix/main.cf
myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, $mydomain, localhost
relayhost =
mynetworks = 127.0.0.0/8
home_mailbox = Maildir/
smtpd_banner = $myhostname ESMTP
# TLS settings
smtpd_use_tls = yes
smtpd_tls_cert_file = /etc/ssl/certs/mail.crt
smtpd_tls_key_file = /etc/ssl/private/mail.key
smtp_tls_security_level = may
systemctl restart postfix
Step 4: Install SSL Certificate
apt install certbot -y
certbot certonly --standalone -d mail.yourdomain.com
# Update Postfix to use Let's Encrypt cert
postconf -e "smtpd_tls_cert_file=/etc/letsencrypt/live/mail.yourdomain.com/fullchain.pem"
postconf -e "smtpd_tls_key_file=/etc/letsencrypt/live/mail.yourdomain.com/privkey.pem"
systemctl restart postfix
Step 5: Install and Configure OpenDKIM
apt install opendkim opendkim-tools -y
# /etc/opendkim.conf
Domain yourdomain.com
KeyFile /etc/opendkim/keys/yourdomain.com/mail.private
Selector mail
Socket inet:8891@localhost
# Generate keys
mkdir -p /etc/opendkim/keys/yourdomain.com
opendkim-genkey -s mail -d yourdomain.com -D /etc/opendkim/keys/yourdomain.com/
chown -R opendkim:opendkim /etc/opendkim/
# Connect Postfix to OpenDKIM (add to main.cf):
milter_default_action = accept
milter_protocol = 6
smtpd_milters = inet:localhost:8891
non_smtpd_milters = inet:localhost:8891
systemctl restart opendkim postfix
Step 6: Configure DNS Records
MX Record: @ → mail.yourdomain.com (priority 10)
A Record: mail → YOUR.SERVER.IP
TXT Record: @ → "v=spf1 ip4:YOUR.SERVER.IP ~all"
TXT Record: mail._domainkey → (paste from mail.txt file)
TXT Record: _dmarc → "v=DMARC1; p=none; rua=mailto:admin@yourdomain.com"
Step 7: Test Your SMTP Server
# Send a test email
echo "Test SMTP" | mail -s "Subject: Test" recipient@gmail.com
# Check mail logs
tail -f /var/log/mail.log
# Test SMTP authentication
telnet mail.yourdomain.com 25
Step 8: Check Blacklists and Reputation
After setup, verify your IP is not blacklisted:
- MXToolbox Blacklist Check (mxtoolbox.com/blacklists)
- mail-tester.com — sends a test score from 1–10
- Google Postmaster Tools — monitor Gmail delivery rates
A correctly configured SMTP server on a fresh, clean IP will pass all authentication checks and reach the inbox reliably from day one.