Dovecot — IMAP/POP3 Server
If you like this project, consider supporting me on Buy Me a Coffee ☕️
tags:
- dovecot
- imap
- pop3
- sysadmin
-
linux
📧 Dovecot Cheatsheet
Description
Dovecot is a secure, open-source IMAP and POP3 server with Maildir/mbox storage, modern authentication (SCRAM), and strong performance. Works with Postfix and LDAP. / Dovecot — безопасный open-source сервер IMAP и POP3 с Maildir/mbox, современной аутентификацией (SCRAM) и высокой производительностью. Работает с Postfix и LDAP.
Common use cases / Типовые сценарии:
- IMAP/POP3 for mailboxes / IMAP/POP3 для почтовых ящиков
- Mail storage backend for Postfix / Хранилище почты для Postfix
- Webmail backend (Roundcube, SOGo) / Бэкенд для webmail
- LDAP-backed auth / Аутентификация через LDAP
Status: Actively maintained (Dovecot Foundation / Pigeonhole). Alternatives: Courier IMAP, Cyrus IMAP, Zimbra. / Статус: активно развивается; альтернативы — Courier, Cyrus IMAP, Zimbra.
Default ports: 143/tcp (IMAP), 993/tcp (IMAPS), 110/tcp (POP3), 995/tcp (POP3S).
Paths: config /etc/dovecot/; Maildir /var/mail/vhosts/<DOMAIN>/<USER>/.
Cross-reference: Postfix, OpenLDAP, SSL/TLS.
Installation
Install Dovecot / Установка Dovecot
# Debian/Ubuntu
apt install dovecot-imapd dovecot-pop3d dovecot-sieve
# RHEL/Rocky/Alma/Fedora
dnf install dovecot
dovecot --version
systemctl enable --now dovecot
Configuration
Main files / Основные файлы
/etc/dovecot/dovecot.conf
/etc/dovecot/conf.d/10-mail.conf
/etc/dovecot/conf.d/10-auth.conf
/etc/dovecot/conf.d/10-ssl.conf
/etc/dovecot/conf.d/10-master.conf
/etc/dovecot/conf.d/10-logging.conf
dovecot.conf / dovecot.conf
/etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp
listen = *, ::
mail_location = maildir:/var/mail/vhosts/%d/%n
ssl = required
ssl_cert = </etc/ssl/certs/dovecot.pem
ssl_key = </etc/ssl/private/dovecot.key
auth_mechanisms = plain login
disable_plaintext_auth = yes
auth_username_format = %Lu
mail_debug = no
Maildir setup / Настройка Maildir
mkdir -p /var/mail/vhosts/example.com/alice
chown -R vmail:vmail /var/mail/vhosts/example.com/alice
TLS certs / TLS-сертификаты
openssl req -new -x509 -days 365 -nodes \
-out /etc/ssl/certs/dovecot.pem \
-keyout /etc/ssl/private/dovecot.key \
-subj "/CN=<MAIL_HOST>"
chmod 600 /etc/ssl/private/dovecot.key
chown root:root /etc/ssl/private/dovecot.key
systemctl restart dovecot
Core Management
doveconf / doveconf
doveconf
doveconf -n
doveconf -h
doveconf mail_location
doveconf ssl_cert
Test connection / Тест подключения
openssl s_client -connect <MAIL_HOST>:993 -crlf
# LOGIN <USER> <PASSWORD>
# LIST "" ""
Sysadmin Operations
Logs / Логи
journalctl -u dovecot --no-pager -n 50
tail -f /var/log/mail.log
doveadm log errors
Logrotate / Ротация логов
/etc/logrotate.d/dovecot
/var/log/mail.log {
weekly
rotate 4
compress
delaycompress
missingok
notifempty
sharedscripts
postrotate
systemctl reload dovecot >/dev/null 2>&1 || true
endscript
}
Security
Hardening / Ужесточение
- Require TLS:
ssl = required/ Требуйте TLS - Disable plaintext auth:
disable_plaintext_auth = yes/ Отключите plaintext - Use SCRAM-SHA-256 if possible / Используйте SCRAM-SHA-256
- Protect SSL private key (0600 root) / Защитите приватный ключ
- Restrict who can read Maildir / Ограничьте доступ к Maildir
- Keep Dovecot patched / Обновляйте Dovecot
- Monitor auth failures / Мониторьте неудачные auth
# /etc/dovecot/conf.d/10-ssl.conf
# ssl = required
# ssl_min_protocol = TLSv1.2
Backup and Restore
Backup / Резервное копирование
tar czf /var/backups/dovecot-$(date +%F).tar.gz \
/etc/dovecot /var/mail/vhosts
Restore / Восстановление
systemctl stop dovecot
tar xzf /var/backups/dovecot-<DATE>.tar.gz -C /
chown -R vmail:vmail /var/mail/vhosts
systemctl start dovecot
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Auth failed | Wrong credentials / PAM | Check auth config; passwords |
| No mail location | mail_location unset | Set mail_location |
| TLS errors | Cert path / expired | Check cert; regenerate |
| Connection refused | Firewall / service down | Open 143/993; start dovecot |
| Permission denied Maildir | Ownership | chown vmail:vmail |
doveconf -n
doveadm auth test <USER>
systemctl status dovecot
Comparison Tables
IMAP servers / IMAP-серверы
| Server | Notes |
|---|---|
| Dovecot | Secure, flexible, fast |
| Courier IMAP | Legacy, stable |
| Cyrus IMAP | Scalable, complex |
| Zimbra | Full suite (paid/community) |
Production Runbooks
Runbook: Deploy IMAP with Postfix / Развёртывание IMAP с Postfix
- Install Dovecot and Postfix / Установить Dovecot и Postfix
- Generate TLS certificates / Создать TLS-сертификаты
- Configure Maildir location; create vmail user / Настроить Maildir
- Configure Dovecot auth (PAM or SQL or LDAP) / Настроить аутентификацию
- Point Postfix to Dovecot LMTP for delivery / Настроить LMTP-доставку
- Open 993/995 (and 143 if needed) / Открыть порты
- Restart both services; test IMAPS login / Перезапустить; проверить вход
- Document mailbox provisioning process / Задокументировать процесс создания ящиков
Runbook: Provision new mailbox / Создание нового ящика
- Create system/vmail user if needed / Создать пользователя
- Create Maildir directory / Создать Maildir
- chown vmail:vmail on directory / Исправить владельца
- Add user to auth backend (PAM/SQL/LDAP) / Добавить в auth-бэкенд
- Test
doveadm auth test/ Проверить auth - Test IMAPS login from client / Проверить вход
- Document quota if configured / Задокументировать квоту
Documentation Links
- Dovecot docs — https://doc.dovecot.org/
- Dovecot wiki — https://wiki.dovecot.org/
- Pigeonhole (sieve) — https://doc.dovecot.org/configuration_manual/sieve/
- Maildir format — https://cr.yp.to/proto/maildir.html