Dovecot is the IMAP server that lets mail apps and webmail read mailboxes. Paired with Postfix it forms a complete self-hosted mail server: Postfix receives and sends, Dovecot stores and serves. This guide sets up Dovecot with system users, TLS and Postfix integration.
Before you start
- A Linux VPS with Postfix already accepting mail for your domain (MX record pointing to the server,
mydestinationincluding your domain). - A TLS certificate for the mail hostname, for example from Let's Encrypt for
mail.example.com. - Ports 25, 587 and 993 open.
Tip: Self-hosted email takes ongoing care. On MdmHost cPanel hosting, Dovecot and Exim are already configured and maintained for you.
Install Dovecot
- Ubuntu/Debian:
sudo apt install -y dovecot-imapd dovecot-lmtpd - AlmaLinux/Rocky:
sudo dnf install -y dovecot && sudo systemctl enable dovecot
Settings are split across /etc/dovecot/conf.d/.
Configure mail storage
In 10-mail.conf:
mail_location = maildir:~/MaildirEach user's mail is stored as files in ~/Maildir.
Require TLS and secure authentication
- In
10-ssl.conf:ssl = required ssl_cert = </etc/letsencrypt/live/mail.example.com/fullchain.pem ssl_key = </etc/letsencrypt/live/mail.example.com/privkey.pem ssl_min_protocol = TLSv1.2 - In
10-auth.conf:disable_plaintext_auth = yes auth_mechanisms = plain login - In
10-master.conf, disable plain IMAP on 143 by setting itsport = 0insideinet_listener imap, and keepimapson 993.
Deliver mail from Postfix via LMTP
- In
10-master.conf, expose LMTP to Postfix:service lmtp { unix_listener /var/spool/postfix/private/dovecot-lmtp { mode = 0600 user = postfix group = postfix } } - In Postfix's
main.cf:mailbox_transport = lmtp:unix:private/dovecot-lmtp
Let Postfix authenticate users through Dovecot
- In Dovecot's
10-master.conf:service auth { unix_listener /var/spool/postfix/private/auth { mode = 0660 user = postfix group = postfix } } - In Postfix's
master.cf, enable the submission service on port 587 with:submission inet n - y - - smtpd -o smtpd_tls_security_level=encrypt -o smtpd_sasl_auth_enable=yes -o smtpd_sasl_type=dovecot -o smtpd_sasl_path=private/auth -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject - Restart both:
sudo systemctl restart dovecot postfix.
Test the server
- Check the config:
doveconf -n. - Test TLS on IMAP:
openssl s_client -connect mail.example.com:993– you should see the Dovecot greeting. - Add the account in a mail app: IMAP
mail.example.comport 993 SSL/TLS; SMTP port 587 STARTTLS; username is the Linux user. - Send a message to the account and watch
journalctl -u dovecot -ffor a successful LMTP delivery.
Troubleshooting
- Login fails: check
journalctl -u dovecot; make sure the user exists and has a password. - Postfix "connect to private/dovecot-lmtp: No such file": the socket path or permissions in
10-master.confdo not match. - Certificate warnings in mail apps: the certificate does not cover the hostname clients use.
- Mail delivered to /var/mail instead of Maildir:
mailbox_transportis not set in Postfix.
FAQ: Dovecot IMAP server
Can I use virtual users instead of Linux accounts?
Yes. Dovecot supports password files and SQL databases for virtual mailboxes; it is more setup but scales better.
Should I enable POP3?
Only if users need it. IMAP keeps mail in sync across devices, which suits most people.
How do I add spam filtering?
Add Rspamd or SpamAssassin as a Postfix milter, and use Dovecot's Sieve plugin to file spam into a Junk folder.
