How to install Postfix and Dovecot for email
Updated 11/29/2026
Postfix handles sending and receiving email (SMTP), and Dovecot handles access to mailboxes (IMAP). Together they form the base of a classic mail server.
1. Install Postfix
apt-get update -y
apt-get install -y postfix
Choose "Internet Site" and enter your domain name during configuration.
2. Install Dovecot
apt-get install -y dovecot-imapd dovecot-pop3d
3. Configure storage (Maildir)
In /etc/dovecot/conf.d/10-mail.conf:
mail_location = maildir:~/Maildir
4. Enable TLS
Email must be encrypted. Use a Let's Encrypt certificate, see free SSL certificate, and point Postfix and Dovecot to it.
5. Open the ports
ufw allow 25/tcp
ufw allow 587/tcp
ufw allow 993/tcp
Important
Manual setup is educational but laborious. For production, a solution like Mailcow is easier to maintain. Either way, configure SPF, DKIM and DMARC.
Put this guide into practice on your own VPS
EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.
See pricingRelated tutorials
Newsletters with Listmonk: lists, campaigns and delivery
Send newsletters from your own server with no per-subscriber fee: SMTP, lists, signup forms, campaigns and domain reputation.
Updated 11/29/2026EmailShould you run your own mail server?
The pros, cons and what you need to know before hosting email on your own server.
Updated 11/29/2026EmailHow to secure a mail server
A misconfigured mail server becomes a spam source. Here are the essential security rules.
Updated 11/29/2026