How to Set Up a Complete Mail Server (Postfix + Dovecot + SPF/DKIM/DMARC)

This guide ties together everything needed for a fully functional, properly authenticated self-hosted mail server — combining the individual pieces covered in other guides into one end-to-end checklist and order of operations.

What You'll End Up With

  • Postfix handling outbound/inbound SMTP
  • Dovecot providing IMAP/POP3 access for mail clients
  • Full SPF, DKIM, and DMARC authentication
  • Correct reverse DNS (PTR)
  • TLS encryption throughout

Prerequisites

  • A dedicated VPS with a dedicated IPv4 address
  • A domain you control with DNS access
  • Root or sudo access

Step 1 — Set the Hostname

sudo hostnamectl set-hostname mail.yourdomain.com

Step 2 — Create the Forward DNS (A) Record

Type: A
Name: mail
Value: YOUR_SERVER_IP

Step 3 — Request the PTR Record from Your Provider

See How to Set Up Reverse DNS (PTR/rDNS) for Email Deliverability for the full process.

Step 4 — Obtain a TLS Certificate

sudo apt install certbot -y
sudo certbot certonly --standalone -d mail.yourdomain.com

Step 5 — Install and Configure Postfix

Follow How to Install and Configure Postfix as a Mail Transfer Agent in full.

Step 6 — Install and Configure Dovecot

Follow How to Install and Configure Dovecot for IMAP/POP3 in full, including connecting it to Postfix for SASL authentication.

Step 7 — Configure DKIM Signing

sudo apt install opendkim opendkim-tools -y
sudo mkdir -p /etc/opendkim/keys/yourdomain.com
sudo opendkim-genkey -s default -d yourdomain.com -D /etc/opendkim/keys/yourdomain.com

Connect OpenDKIM to Postfix:

sudo nano /etc/postfix/main.cf
milter_default_action = accept
milter_protocol = 6
smtpd_milters = inet:localhost:8891
non_smtpd_milters = inet:localhost:8891
sudo systemctl restart opendkim postfix

Step 8 — Publish DNS Records

Add all three at once:

SPF (TXT @):        v=spf1 ip4:YOUR_SERVER_IP -all
DKIM (TXT default._domainkey): v=DKIM1; k=rsa; p=YOUR_PUBLIC_KEY
DMARC (TXT _dmarc):  v=DMARC1; p=none; rua=mailto:[email protected]

See How to Configure SPF, DKIM, and DMARC (Complete Guide) for full detail on each.

Step 9 — Create Mailboxes

sudo adduser john

Each Linux system user automatically gets a mailbox under Dovecot's default Maildir configuration.

Step 10 — Configure the Firewall

sudo ufw allow 25/tcp
sudo ufw allow 587/tcp
sudo ufw allow 465/tcp
sudo ufw allow 993/tcp
sudo ufw allow 995/tcp

Step 11 — Full End-to-End Test

  1. Send a test email to a Gmail account
  2. Open it and select "Show original"
  3. Confirm SPF, DKIM, and DMARC all show PASS
  4. Configure a mail client (Thunderbird, Outlook, or your phone) using the IMAP/SMTP settings from the Dovecot guide, and confirm you can send and receive

Step 12 — Warm Up Before Sending Volume

If this server will send marketing or bulk mail, follow IP Warm-Up: A Safe 30-Day Schedule for New Sending IPs before ramping up volume.

Common Errors

See the dedicated troubleshooting guide: How to Troubleshoot Email Not Sending or Going to Spam.

Best Practices

  • Complete every step above before sending any real mail — partial configuration is a common cause of poor deliverability
  • Test with Gmail's header inspection after every significant configuration change
  • Keep the server updated and monitor logs regularly

Continue Reading

Browse more articles in Email Hosting & Deliverability.

  • mail server setup, postfix dovecot, self hosted email server, complete mail server
  • 0 Utilisateurs l'ont trouvée utile
Cette réponse était-elle pertinente?

Articles connexes

How to Set Up a VPS for Email Marketing (Complete Guide)

Running your own email marketing infrastructure on a VPS gives you full control over...

How to Configure SPF, DKIM, and DMARC (Complete Guide)

SPF, DKIM, and DMARC are the three DNS-based email authentication standards that Gmail, Outlook,...

How to Set Up Reverse DNS (PTR/rDNS) for Email Deliverability

Reverse DNS (PTR record) maps your server's IP address back to a hostname — the opposite of...

IP Warm-Up: A Safe 30-Day Schedule for New Sending IPs

Mailbox providers like Gmail and Outlook monitor sending behavior closely and treat sudden...

Best Email Marketing Software for a VPS (MailWizz, Mautic, Listmonk & More)

Choosing the right self-hosted email marketing platform affects deliverability, ease of...