Dovecot is the leading open-source IMAP and POP3 server. It handles the storage and retrieval side of email — while Postfix delivers mail, Dovecot lets your mail clients (Thunderbird, Apple Mail, etc.) read it. Together they form the backbone of a self-hosted mail server.
Prerequisites
- Ubuntu 22.04 with Postfix already installed
- A domain with valid DNS records
- TLS certificate (Let’s Encrypt recommended)
Step 1: Install Dovecot
sudo apt update
sudo apt install dovecot-core dovecot-imapd dovecot-pop3d -y
Verify the version:
dovecot --version
Step 2: Configure Maildir Storage
Dovecot supports two storage formats: mbox (single file) and Maildir (directory per message). Maildir is recommended for performance and reliability.
Edit /etc/dovecot/conf.d/10-mail.conf:
mail_location = maildir:~/Maildir
This matches Postfix’s home_mailbox = Maildir/ setting. Each user’s mail will be stored in ~username/Maildir/.
Step 3: Configure Authentication
Edit /etc/dovecot/conf.d/10-auth.conf:
# Allow plain-text auth only over TLS
disable_plaintext_auth = yes
auth_mechanisms = plain login
Dovecot uses system users (PAM) by default, which is fine for small setups. For virtual users, you’d use auth-sql.conf.ext or auth-ldap.conf.ext.
Step 4: Enable TLS
Edit /etc/dovecot/conf.d/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
ssl_cipher_list = HIGH:!SSLv3:!aNULL
Note the
<prefix — Dovecot reads the cert file content using this syntax.
Step 5: Configure Listening Ports
Edit /etc/dovecot/conf.d/10-master.conf to enable IMAP (port 143/993) and POP3 (port 110/995):
service imap-login {
inet_listener imap {
port = 143
}
inet_listener imaps {
port = 993
ssl = yes
}
}
service pop3-login {
inet_listener pop3 {
port = 110
}
inet_listener pop3s {
port = 995
ssl = yes
}
}
Step 6: Integrate with Postfix (SASL)
Dovecot can provide SASL authentication to Postfix, allowing it to authenticate outgoing mail submission. Edit 10-master.conf to expose the auth socket:
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
}
Then in Postfix’s /etc/postfix/main.cf, add:
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
Reload both services:
sudo systemctl reload dovecot postfix
Step 7: Test IMAP Access
Use openssl to test IMAP over TLS:
openssl s_client -connect mail.example.com:993
After connecting, you should see the Dovecot greeting:
* OK [CAPABILITY IMAP4rev1 ...] Dovecot ready.
Log in with:
a1 LOGIN username password
Step 8: Create a System User for Testing
sudo useradd -m -s /bin/bash testuser
sudo passwd testuser
Now you can configure a mail client (Thunderbird, etc.) with:
- IMAP server:
mail.example.com, port 993, SSL/TLS - SMTP server:
mail.example.com, port 587, STARTTLS - Username:
testuser
Common Issues
“Authentication failed” — Check /var/log/mail.log and /var/log/auth.log. Ensure disable_plaintext_auth = yes is set and your client is using SSL.
“Permission denied” on Maildir — Check that the Maildir directory exists: sudo -u testuser mkdir -p ~/Maildir/{cur,new,tmp}.
Dovecot not starting — Run sudo dovecot -F to start in foreground and see errors. Check doveconf -n for configuration summary.
What’s Next
With Postfix + Dovecot running, your mail stack is functional. The next critical step is email authentication (SPF, DKIM, DMARC) to ensure your messages aren’t rejected or flagged as spam.