How to install Postfix and Dovecot for email
Updated 7/20/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
How to filter spam with Rspamd
Rspamd is a modern, fast spam filter. Here is how to use it to keep your inbox clean.
Updated 7/20/2026EmailHow to secure a mail server
A misconfigured mail server becomes a spam source. Here are the essential security rules.
Updated 7/20/2026EmailHow to use an SMTP relay for reliable delivery
An SMTP relay sends your emails through a service with good reputation, ideal for apps without their own mail server.
Updated 7/20/2026