Dovecot is the most widely used open-source IMAP/POP3 server, letting mail clients (phones, webmail, desktop apps) retrieve and synchronize messages stored on your mail server. This guide pairs with Postfix to complete a self-hosted mail setup.
Prerequisites
- Postfix already installed and configured
- Ubuntu 22.04/24.04 or Debian 11/12 VPS
- Root or sudo access
Step 1 — Install Dovecot
sudo apt update
sudo apt install dovecot-core dovecot-imapd dovecot-pop3d -y
Step 2 — Configure Mail Storage Location
sudo nano /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir
Step 3 — Enable IMAP and POP3
sudo nano /etc/dovecot/conf.d/10-master.conf
Confirm the IMAP and POP3 services are uncommented and listening.
Step 4 — Configure Authentication
sudo nano /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = yes
auth_mechanisms = plain login
disable_plaintext_auth = yes requires encryption for authentication — essential once TLS is configured, to prevent credentials from being sent in plaintext.
Step 5 — Enable TLS
sudo nano /etc/dovecot/conf.d/10-ssl.conf
ssl = required
ssl_cert = </etc/letsencrypt/live/mail.yourdomain.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.yourdomain.com/privkey.pem
Step 6 — Restart Dovecot
sudo systemctl restart dovecot
sudo systemctl enable dovecot
Step 7 — Open Required Ports
sudo ufw allow 993/tcp
sudo ufw allow 995/tcp
Step 8 — Connect Postfix to Dovecot for Authentication
Edit Postfix to use Dovecot's SASL authentication for outbound mail submission:
sudo nano /etc/postfix/main.cf
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
sudo systemctl restart postfix dovecot
Step 9 — Test the IMAP Connection
openssl s_client -connect mail.yourdomain.com:993
You should see a successful TLS handshake followed by a Dovecot greeting.
Step 10 — Configure a Mail Client
| Setting | Value |
|---|---|
| IMAP Server | mail.yourdomain.com |
| IMAP Port | 993 (SSL/TLS) |
| SMTP Server | mail.yourdomain.com |
| SMTP Port | 587 (STARTTLS) |
Common Errors
"Connection refused" on port 993 — confirm Dovecot is running and the firewall rule was added:
sudo systemctl status dovecot
Authentication failed — verify the user's system account exists and password is correct; Dovecot commonly authenticates against system accounts or a separate user database depending on configuration.
TLS handshake errors — verify certificate paths and that the certificate is valid for the exact hostname being used to connect.
Best Practices
- Always require TLS (
ssl = required) for both authentication and data transfer - Disable plaintext authentication once TLS is confirmed working
- Keep certificates renewed — see How to Renew and Auto-Renew Let's Encrypt Certificates
FAQ
Do I need both IMAP and POP3?
Not necessarily — IMAP alone is sufficient for most modern use cases; only enable POP3 if a specific client or workflow requires it.
Related Articles
- How to Install and Configure Postfix as a Mail Transfer Agent
- SMTP vs IMAP vs POP3: Understanding Email Protocols
- How to Set Up a Complete Mail Server (Postfix + Dovecot + SPF/DKIM/DMARC)
