Dovecot
Chapter 79: Dovecot IMAP/POP3 Server
Section titled “Chapter 79: Dovecot IMAP/POP3 Server”Comprehensive Dovecot Configuration and Management
Section titled “Comprehensive Dovecot Configuration and Management”79.1 Dovecot Architecture Overview
Section titled “79.1 Dovecot Architecture Overview”What is Dovecot?
Section titled “What is Dovecot?”Dovecot is an open-source IMAP and POP3 server for Linux and UNIX-like systems. Known for its security, simplicity, and high performance, it’s widely deployed in production email environments ranging from small organizations to large-scale mail services.
┌────────────────────────────────────────────────────────────────────────┐│ DOVECOT ARCHITECTURE │├────────────────────────────────────────────────────────────────────────┤│ ││ ┌─────────────────────────────────────────────────────────────────┐ ││ │ CLIENT CONNECTIONS │ ││ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ ││ │ │ Thunder-│ │ iOS │ │ Outlook │ │ Web │ │ ││ │ │ bird │ │ Mail │ │ │ │ Mail │ │ ││ │ └────┬────┘ └────┬────┘ └────┬────┘ └────┬────┘ │ ││ └───────┼───────────┼───────────┼───────────┼──────────────────┘ ││ │ │ │ │ ││ │ │ │ │ ││ ┌───────┴───────────┴───────────┴───────────┴──────────────────┐ ││ │ DOVECOT SERVER │ ││ │ │ ││ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ ││ │ │ IMAP (143) │ │ IMAPS (993) │ │ POP3 (110) │ │ ││ │ │ POP3S(995) │ │ │ │ │ │ ││ │ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │ ││ └─────────┼─────────────────┼─────────────────┼────────────────┘ ││ │ │ │ ││ ┌─────────┴─────────────────┴─────────────────┴────────────────┐ ││ │ AUTHENTICATION LAYER │ ││ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ ││ │ │ PAM │ │ LDAP │ │ SQL │ │ passwd │ │ ││ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ ││ └──────────────────────────────────────────────────────────────┘ ││ │ ││ ┌─────────┴──────────────────────────────────────────────────┐ ││ │ MAIL STORAGE LAYER │ ││ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ ││ │ │ Maildir │ │ mbox │ │ dbox │ │ imapc │ │ ││ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ ││ └──────────────────────────────────────────────────────────────┘ ││ │└────────────────────────────────────────────────────────────────────────┘Key Features
Section titled “Key Features”| Feature | Description | Benefit |
|---|---|---|
| High Performance | Optimized for modern hardware, multi-threaded | Handles thousands of concurrent users |
| Security First | SELinux support, privilege separation, encrypted passwords | Protects against attacks |
| Flexible Auth | PAM, LDAP, SQL, passwd, Kerberos | Integrates with existing infrastructure |
| Multiple Formats | Maildir, mbox, dbox, remote IMAP | Migration flexibility |
| Quota Support | User and mailbox quotas | Resource management |
| ACLs | IMAP ACL extension | Shared folder management |
| Sieve | Server-side filtering | Automated email organization |
| Replication | dsync-based replication | High availability |
Protocol Comparison
Section titled “Protocol Comparison”┌────────────────────────────────────────────────────────────────────────┐│ IMAP vs POP3 COMPARISON │├────────────────────────────────────────────────────────────────────────┤│ ││ ┌─────────────────────┬─────────────────────┬────────────────────┐ ││ │ Feature │ IMAP │ POP3 │ ││ ├─────────────────────┼─────────────────────┼────────────────────┤ ││ │ Default Port │ 143 (plain) │ 110 (plain) │ ││ │ Encrypted Port │ 993 (IMAPS) │ 995 (POP3S) │ ││ │ Mail Storage │ On server │ Downloaded │ ││ │ Multiple Devices │ Yes (sync) │ No │ ││ │ Offline Access │ Limited │ Full │ ││ │ Bandwidth │ More efficient │ Less efficient │ ││ │ Server Resources │ Higher │ Lower │ ││ │ Complexity │ Higher │ Lower │ ││ │ Use Case │ Multi-device access │ Single computer │ ││ └─────────────────────┴─────────────────────┴────────────────────┘ ││ ││ RECOMMENDATION: Use IMAP for most scenarios ││ - Cross-device synchronization ││ - Webmail integration ││ - Mobile device support ││ │└────────────────────────────────────────────────────────────────────────┘79.2 Installation
Section titled “79.2 Installation”Package Installation
Section titled “Package Installation”# Debian/Ubuntusudo apt updatesudo apt install dovecot dovecot-imapd dovecot-pop3d dovecot-lucene
# RHEL/CentOS/AlmaLinuxsudo yum install dovecot dovecot-pigeonhole
# Fedorasudo dnf install dovecot dovecot-pigeonhole
# Arch Linuxsudo pacman -S dovecot
# openSUSEsudo zypper install dovecotVerification
Section titled “Verification”# Check versiondovecot --version
# Verify installationdovecot -n
# Check processesps aux | grep dovecot
# Check portsss -tlnp | grep -E "(imap|pop3)"netstat -tlnp | grep -E "(imap|pop3)"79.3 Core Configuration
Section titled “79.3 Core Configuration”Main Configuration File
Section titled “Main Configuration File”# Enable protocolsprotocols = imap pop3
# Listen addresseslisten = *, ::
# IPv6ipv6 = yes
# Base directory for runtime database_dir = /var/run/dovecot/
# Login processesloginProcesses = 32
# Number of IMAP/POP3 processesdefault_process_limit = 1024
# Maximum connections per usermail_max_userip_connections = 50
# Disable version displayversion_avoid = 1Protocol Configuration
Section titled “Protocol Configuration”# Service configurationsservice imap-login { inet_listener imap { port = 143 } inet_listener imaps { port = 993 ssl = yes }
# Process limits process_min_avail = 3 service_count = 0}
service pop3-login { inet_listener pop3 { port = 110 } inet_listener pop3s { port = 995 ssl = yes }
service_count = 0}
# Limit connectionsservice imap { process_limit = 5000 vsz_limit = 256M}
service pop3 { process_limit = 2000 vsz_limit = 256M}Authentication Configuration
Section titled “Authentication Configuration”# Disable plain text auth without SSLdisable_plaintext_auth = yes
# Authentication mechanismsauth_mechanisms = plain login apop
# User databaseuserdb { driver = passwd args = blocking=yes}
# Password databasepassdb { driver = pam args = session=yes dovecot}
# LDAP example# passdb {# driver = ldap# args = /etc/dovecot/dovecot-ldap.conf# }
# SQL example# passdb {# driver = sql# args = /etc/dovecot/dovecot-sql.conf# }
# Kerberos example# auth_mechanisms = plain login gssapi# passdb {# driver = gssapi# args = realm=EXAMPLE.COM# }
# Default realm for LOGIN mechanismauth_default_realm = example.comMail Location Configuration
Section titled “Mail Location Configuration”# Mail location (Maildir format - recommended)mail_location = maildir:~/Maildir
# Alternative: mbox format# mail_location = mbox:~/mail:INBOX=/var/mail/%u
# Alternative: dbox format (Dovecot's high-performance format)# mail_location = sdbox:~/mdbox
# Create mail directories if missingmail_create_maildir_if_missing = yes
# Namespace configurationnamespace inbox { inbox = yes location =
mailbox Sent { auto = subscribe special_use = \Sent }
mailbox Drafts { auto = subscribe special_use = \Drafts }
mailbox Trash { auto = subscribe special_use = \Trash }
mailbox Archive { auto = subscribe special_use = \Archive }
mailbox Spam { auto = subscribe special_use = \Junk }}
# Mailbox namingmailbox_names = Trash, Sent, Drafts, Archive, Spam
# Lockinglock_method = fcntl
# Directory hierarchymail_dir = Maildir
# ACL plugin configurationmail_plugins = aclplugin { acl = vfile}SSL/TLS Configuration
Section titled “SSL/TLS Configuration”# SSL requiredssl = required
# Certificate filesssl_cert = </etc/ssl/certs/dovecot.crtssl_key = </etc/ssl/private/dovecot.keyssl_ca = </etc/ssl/certs/ca-certificates.crt
# DH parametersssl_dh = </etc/dovecot/dh.pem
# Minimum TLS versionssl_min_protocol = TLSv1.2
# Ciphersssl_cipher_list = HIGH:!aNULL:!MD5:!RC4
# Prefer server ciphersssl_prefer_server_ciphers = yes
# Disable compression (CRIME attack)ssl_options = no_compressionGenerating SSL Certificates
Section titled “Generating SSL Certificates”# Generate self-signed certificate (for testing)sudo openssl req -new -x509 -days 365 -nodes \ -out /etc/ssl/certs/dovecot.crt \ -keyout /etc/ssl/private/dovecot.key \ -subj "/C=US/ST=State/L=City/O=Org/CN=mail.example.com"
# Generate DH parameterssudo openssl dhparam -out /etc/dovecot/dh.pem 4096
# Set permissionssudo chmod 640 /etc/ssl/private/dovecot.keysudo chown root:dovecot /etc/ssl/private/dovecot.key
# Using Let's Encrypt (recommended for production)# Install certbot, then:sudo certbot certonly --standalone -d mail.example.comsudo cp /etc/letsencrypt/live/mail.example.com/fullchain.pem /etc/ssl/certs/dovecot.crtsudo cp /etc/letsencrypt/live/mail.example.com/privkey.pem /etc/ssl/private/dovecot.key
# Reload Dovecotsudo systemctl reload dovecot79.4 Advanced Configuration
Section titled “79.4 Advanced Configuration”Quota Configuration
Section titled “Quota Configuration”# Install quota plugin# apt install dovecot-pop3d-imapd (Debian)
# Enable quota pluginmail_plugins = $mail_plugins quota
# Quota backendplugin { quota = maildir:user quota_rule = *:storage=10GB quota_rule2 = *:messages=100000 quota_warning = storage=95%% quota-warning 95 %u quota_warning2 = storage=80%% quota-warning 80 %u}
# Service for quota warningsservice quota-warning { executable = script /usr/local/bin/quota-warning.sh user = dovecot unix_listener quota-warning { user = dovecot }}#!/bin/bashPERCENT=$1USER=$2
cat << EOF | /usr/lib/dovecot/dovecot-lda -d $USER -o "plugin/quota="From: postmaster@example.comSubject: Quota Warning
Your mailbox is now at $PERCENT% of its quota.Please delete some messages to free up space.EOFSieve Filtering
Section titled “Sieve Filtering”# Install pigeonhole (Sieve plugin)# apt install dovecot-pigeonhole
# Enable sievemail_plugins = $mail_plugins sieve
plugin { sieve = ~/.dovecot.sieve sieve_dir = ~/sieve sieve_default = /etc/dovecot/sieve/default.sieve sieve_global_dir = /etc/dovecot/sieve/global/}
# Vacation auto-replyplugin { sieve_vacation_use_domain = yes sieve_vacation_default_period = 7d sieve_vacation_max_period = 30d}require ["fileinto", "vacation"];
# Spam to Junk folderif header :contains "X-Spam-Flag" "YES" { fileinto "Junk"; stop;}
# Archive old messagesif currentdate :year >= 2024 { fileinto "Archive.2024";}
# Vacation auto-reply# vacation :days 7 :subject "Out of Office" "I'm currently out of office.";ACL Configuration
Section titled “ACL Configuration”# Enable ACL pluginmail_plugins = $mail_plugins acl
# ACL file locationplugin { acl = vfile acl_shared_dict = file:/var/lib/dovecot/shared-mailboxes}
# IMAP ACL extensionprotocol imap { mail_plugins = $mail_plugins acl imap_acl}# Per-user ACL in Maildir# ~/Maildir/shared:user@example.com=lrswipkxtecda
# Global ACL# /etc/dovecot/dovecot-acl
# Example: Grant access to shared folder# user=admin@example.com lrwstipekxa# group=team@example.com lrwstipekxaReplication (High Availability)
Section titled “Replication (High Availability)”# Enable replicationmail_plugins = $mail_plugins notify replication
plugin { replication_max_conns = 10 sync_time_to_live = 7d replicator_rows_per_checkpoint = 1000 replicator_sync_time_to_live = 1d}
# Replication destinationservice replicator { process_min_avail = 1 user = vmail}
# Dovecot director for load balancing (in master-slave setup)# See Chapter 80: Email Security for HA setup79.5 Database Integration
Section titled “79.5 Database Integration”MySQL/MariaDB
Section titled “MySQL/MariaDB”driver = mysqlconnect = host=localhost dbname=mailserver user=mailuser password=secretdefault_pass_scheme = SHA256-CRYPT
# Password querypassword_query = SELECT email AS user, password FROM mailbox WHERE email = '%u' AND active = '1'
# User queryuser_query = SELECT CONCAT('/var/vmail/', maildir) AS home, \ CONCAT('maildir:', CONCAT('/var/vmail/', maildir)) AS mail, \ 5000 AS uid, 5000 AS gid, \ CONCAT('*:bytes=', quota) AS quota_rule \ FROM mailbox WHERE email = '%u' AND active = '1'PostgreSQL
Section titled “PostgreSQL”driver = pgsqlconnect = host=localhost dbname=mailserver user=mailuser password=secretdefault_pass_scheme = SHA256-CRYPT
password_query = SELECT email AS user, password FROM mailbox WHERE email = '%u' AND active = true
user_query = SELECT '/var/vmail/' || maildir AS home, \ 'maildir:/var/vmail/' || maildir AS mail, \ 5000 AS uid, 5000 AS gid, \ '*:bytes=' || quota AS quota_rule \ FROM mailbox WHERE email = '%u' AND active = truehosts = ldap.example.com:389dn = cn=admin,dc=example,dc=comdnpass = secret
# LDAP search basebase = ou=people,dc=example,dc=com
# User lookupuser_filter = (&(objectClass=posixAccount)(mail=%u))
# Attribute mappinguser_attrs = mail=mail,homeDirectory=home,uidNumber=uid,gidNumber=gid
# Password lookuppass_filter = (&(objectClass=posixAccount)(mail=%u))pass_attrs = userPassword=password79.6 Management and Administration
Section titled “79.6 Management and Administration”Configuration Testing
Section titled “Configuration Testing”# Show effective configurationdovecot -n
# Test configuration syntaxdovecot -F
# Test specific configuration filedovecot -c /etc/dovecot/dovecot.conf -n
# Check for configuration errorsdovecot -a 2>&1 | grep -i errorUser Management
Section titled “User Management”# Test authenticationdoveadm auth test user@example.com password
# Force authentication cache cleardoveadm auth cache flush
# List mailboxesdoveadm mailbox list -u user@example.com
# List quota usagedoveadm quota get -u user@example.com
# Set quotadoveadm quota set -u user@example.com 5GB
# Force user re-login (kick)doveadm kick user@example.com
# Refresh user databasedoveadm user '*'Mailbox Operations
Section titled “Mailbox Operations”# Create mailboxdoveadm mailbox create -u user@example.com INBOX.Archive
# Delete mailboxdoveadm mailbox delete -u user@example.com INBOX.Archive
# Rename mailboxdoveadm mailbox rename -u user@example.com OldArchive NewArchive
# Subscribe/unsubscribedoveadm mailbox subscribe -u user@example.com INBOX.Archivedoveadm mailbox unsubscribe -u user@example.com INBOX.Archive
# List messagesdoveadm fetch -u user@example.com text mailbox INBOX all
# Expunge deleted messagesdoveadm expunge -u user@example.com mailbox INBOX
# Search messagesdoveadm search -u user@example.com mailbox INBOX flaggedDebugging
Section titled “Debugging”# Enable debug loggingauth_debug = yesauth_verbose = yesmail_debug = yes
# View logs in real-timetail -f /var/log/dovecot.logjournalctl -u dovecot -f
# Debug authenticationdoveadm auth trace user@example.com
# Debug IMAP commands# Add to configuration:# protocol imap {# imap_logging = yes# }
# Connection trackingdoveadm connection listPerformance Monitoring
Section titled “Performance Monitoring”# Check process countps aux | grep dovecot | wc -l
# Connection countsss -tn | grep -E "(imap|pop3)" | wc -l
# Per-user connectionsdoveadm connection list | awk '{print $4}' | sort | uniq -c | sort -rn
# Statisticsdoveadm stats
# Active user countdoveadm user '*' | wc -l79.7 Troubleshooting
Section titled “79.7 Troubleshooting”Common Issues and Solutions
Section titled “Common Issues and Solutions”| Issue | Symptoms | Solution |
|---|---|---|
| Authentication fails | Can’t login | Check auth_debug, verify PAM/LDAP/SQL |
| Slow login | High latency | Check userdb, enable caching |
| Certificate errors | SSL/TLS issues | Regenerate certs, check permissions |
| Quota not working | No quota enforcement | Verify quota plugin loaded |
| Mail not delivered | Bounces | Check dovecot-lda, master configuration |
| High load | Slow response | Reduce connections, increase processes |
| Permission denied | Can’t access mail | Check file permissions, SELinux |
Diagnostic Commands
Section titled “Diagnostic Commands”# Check configuration syntaxdovecot -n
# Check authenticationdoveadm auth test user password
# Check mail locationdoveadm mailbox list -u user
# Check user infodoveadm user user@example.com
# Check logstail -100 /var/log/dovecot.log
# Check system logsjournalctl -u dovecot --since "1 hour ago"
# Check SSLopenssl s_client -connect localhost:993 -showcerts
# Check portsss -tlnp | grep dovecot
# Check SELinux (if enabled)getsebool -a | grep dovecotsetsebool -P dovecot_use_nfs 1Log Analysis
Section titled “Log Analysis”# Failed authenticationgrep "auth failed" /var/log/dovecot.log
# Connection issuesgrep -E "(connection closed|disconnected)" /var/log/dovecot.log
# Quota exceededgrep -i quota /var/log/dovecot.log
# Performance issuesgrep -E "(warning|error)" /var/log/dovecot.log | tail -5079.8 Production Configuration Examples
Section titled “79.8 Production Configuration Examples”Small Office (10-50 users)
Section titled “Small Office (10-50 users)”protocols = imap pop3listen = *base_dir = /var/run/dovecot/
# Authdisable_plaintext_auth = yesauth_mechanisms = plain login
# Mailmail_location = maildir:~/Maildirmail_create_maildir_if_missing = yes
# Users (PAM)userdb { driver = passwd}passdb { driver = pam}
# SSLssl = requiredssl_cert = </etc/ssl/certs/dovecot.crtssl_key = </etc/ssl/private/dovecot.keyssl_min_protocol = TLSv1.2
# Performancedefault_process_limit = 256mail_max_userip_connections = 20
# Logginglog_path = /var/log/dovecot.loginfo_log_path = /var/log/dovecot-info.logEnterprise (1000+ users)
Section titled “Enterprise (1000+ users)”protocols = imap pop3listen = *, [::]base_dir = /var/run/dovecot/
# Auth (LDAP with caching)disable_plaintext_auth = yesauth_mechanisms = plain loginauth_cache_size = 10240auth_cache_ttl = 1 hour
# Mail (dbox for performance)mail_location = sdbox:~/mdboxmail_fsync = always
# Users (LDAP)passdb { driver = ldap args = /etc/dovecot/dovecot-ldap.conf}userdb { driver = ldap args = /etc/dovecot/dovecot-ldap-user.conf}
# Quotamail_plugins = $mail_plugins quotaplugin { quota = maildir:user}
# Sievemail_plugins = $mail_plugins sieveplugin { sieve = file:~/sieve;active=~/.dovecot.sieve}
# SSL/TLSssl = requiredssl_cert = </etc/ssl/certs/dovecot.crtssl_key = </etc/ssl/private/dovecot.keyssl_dh = </etc/dovecot/dh.pemssl_prefer_server_ciphers = yes
# Performance tuningdefault_process_limit = 2048mail_max_userip_connections = 100mail_process_size = 256vsz_limit = 512M
# Logginglog_path = /var/log/dovecot.logauth_verbose = yesmail_debug = no
# Master process for reliabilityservice stats { unix_listener stats-reader { user = dovecot group = dovecot mode = 0660 } unix_listener stats-writer { user = dovecot group = dovecot mode = 0660 }}High Availability Setup
Section titled “High Availability Setup”# On both servers - /etc/dovecot/dovecot.conf# Using keepalived or similar for IP failover
protocols = imap pop3
# Director for load balancinglogin_dir = /var/run/dovecot/loginlogin_chroot = yeslogin_user = dovecot
# Shared storage (NFS or distributed filesystem)mail_location = maildir:/shared/mail/%n
# Performanceservice imap-login { process_min_avail = 4 service_count = 0}79.9 Security Hardening
Section titled “79.9 Security Hardening”Security Checklist
Section titled “Security Checklist”┌────────────────────────────────────────────────────────────────────────┐│ DOVECOT SECURITY CHECKLIST │├────────────────────────────────────────────────────────────────────────┤│ ││ Authentication: ││ □ disable_plaintext_auth = yes ││ □ Use strong password schemes (SHA256-CRYPT, ARGON2) ││ □ Enable authentication caching with encryption ││ □ Rate limiting for failed attempts ││ ││ Encryption: ││ □ ssl = required ││ □ Use valid TLS certificates ││ □ Disable SSLv3, TLS 1.0, 1.1 ││ □ Use strong ciphers ││ □ Configure perfect forward secrecy ││ ││ Access Control: ││ □ Limit connections per IP ││ □ Limit connections per user ││ □ Use firewall to restrict access ││ □ Implement fail2ban for brute force ││ ││ System: ││ □ Run as non-root user ││ □ Restrict config file permissions ││ □ Keep dovecot updated ││ □ Monitor logs regularly ││ □ Enable SELinux/AppArmor ││ │└────────────────────────────────────────────────────────────────────────┘Fail2Ban Integration
Section titled “Fail2Ban Integration”[dovecot]enabled = trueport = pop3,pop3s,imap,imapsfilter = dovecotlogpath = /var/log/dovecot.logmaxretry = 5bantime = 3600findtime = 600[Definition]failregex = auth failed: .+ rip=<HOST> imap-login: .+ rip=<HOST> pop3-login: .+ rip=<HOST>ignoreregex =Firewall Configuration
Section titled “Firewall Configuration”# iptables rulessudo iptables -A INPUT -p tcp --dport 993 -s 10.0.0.0/8 -j ACCEPTsudo iptables -A INPUT -p tcp --dport 995 -s 10.0.0.0/8 -j ACCEPTsudo iptables -A INPUT -p tcp --dport 143 -s 10.0.0.0/8 -j ACCEPTsudo iptables -A INPUT -p tcp --dport 110 -s 10.0.0.0/8 -j ACCEPT
# Drop everything elsesudo iptables -A INPUT -p tcp --dport 993 -j DROPsudo iptables -A INPUT -p tcp --dport 995 -j DROPsudo iptables -A INPUT -p tcp --dport 143 -j DROPsudo iptables -A INPUT -p tcp --dport 110 -j DROP79.10 Interview Questions
Section titled “79.10 Interview Questions”Q1: What is Dovecot and what protocols does it support?
Section titled “Q1: What is Dovecot and what protocols does it support?”Answer: Dovecot is an open-source IMAP and POP3 server for Linux and UNIX systems. It supports:
- IMAP (Internet Message Access Protocol) on ports 143 (plain) and 993 (SSL/TLS)
- POP3 (Post Office Protocol) on ports 110 (plain) and 995 (SSL/TLS)
- LMTP (Local Mail Transfer Protocol) for final delivery
Q2: What is the difference between IMAP and POP3?
Section titled “Q2: What is the difference between IMAP and POP3?”Answer:
- IMAP: Mail stays on server, synchronized across multiple devices, supports folders, supports server-side search, better for mobile and multi-device access
- POP3: Downloads mail to local device, typically deletes from server, limited folder support, simpler but less feature-rich
For most modern use cases, IMAP is recommended.
Q3: How do you configure Dovecot to use LDAP for authentication?
Section titled “Q3: How do you configure Dovecot to use LDAP for authentication?”Answer:
- Install dovecot-ldap package
- Configure
/etc/dovecot/dovecot-ldap.confwith:- LDAP server host and port
- Bind DN and password
- Search base
- User and password filter
- Attribute mappings
- Update
10-auth.confto use LDAP passdb/userdb - Test with
doveadm auth test
Q4: What is the purpose of the mail_location directive?
Section titled “Q4: What is the purpose of the mail_location directive?”Answer:
mail_location specifies where mail is stored and in what format. Common formats:
maildir:~/Maildir- Maildir format (recommended, each message is a file)mbox:~/mail:INBOX=/var/mail/%u- mbox format (single file per mailbox)sdbox:~/mdbox- Dovecot’s high-performance dbox formatimapc:- Remote IMAP (proxy to another server)
Q5: How do you troubleshoot authentication failures in Dovecot?
Section titled “Q5: How do you troubleshoot authentication failures in Dovecot?”Answer:
- Enable debug logging in
10-logging.conf:auth_debug = yesauth_verbose = yes - Check
/var/log/dovecot.logfor details - Test authentication:
doveadm auth test user@domain password - Verify password database configuration
- Check PAM/ LDAP/ SQL configuration
- Verify SSL certificate issues
- Check for SELinux/AppArmor blocking
Q6: What is the difference between dovecot.conf and the conf.d directory?
Section titled “Q6: What is the difference between dovecot.conf and the conf.d directory?”Answer:
dovecot.conf- Main configuration file, includes other config files/etc/dovecot/conf.d/- Modular configuration directory with numbered files:- 10-*.conf - Basic settings
- 15-*.conf - Plugin configurations
- 90-*.conf - Advanced/custom settings
Dovecot reads files in order (10, 15, 20, etc.), so later settings override earlier ones. The !include directive in dovecot.conf loads these files.
Q7: How do you implement quotas in Dovecot?
Section titled “Q7: How do you implement quotas in Dovecot?”Answer:
- Enable quota plugin in configuration:
mail_plugins = $mail_plugins quotaplugin {quota = maildir:userquota_rule = *:storage=5GB}
- Configure quota backend (maildir, dict, sql)
- Set per-user quotas via userdb or SQL
- Optional: Set up quota warnings with doveadm
- Test with
doveadm quota get -u user@domain
Q8: What security measures should be implemented for a production Dovecot server?
Section titled “Q8: What security measures should be implemented for a production Dovecot server?”Answer:
- Use TLS/SSL (ssl = required)
- Disable plaintext auth over unencrypted connections
- Use strong password schemes (SHA256-CRYPT, ARGON2)
- Implement rate limiting
- Use fail2ban for brute force protection
- Restrict access via firewall
- Keep software updated
- Run with minimal privileges
- Enable SELinux/AppArmor
- Monitor logs regularly
- Use valid SSL certificates
Q9: How does Dovecot handle user authentication?
Section titled “Q9: How does Dovecot handle user authentication?”Answer: Dovecot uses a pluggable authentication system:
- Client connects and requests authentication
- Dovecot checks
passdbfor valid credentials - If valid, looks up user in
userdbfor uid, gid, home, mail location - Returns success or failure to client
Supported passdb drivers: pam, ldap, sql, passwd, shadow, bcrypt, argon2 Supported userdb drivers: passwd, ldap, sql, static, nss
Q10: What is the purpose of namespaces in Dovecot?
Section titled “Q10: What is the purpose of namespaces in Dovecot?”Answer: Namespaces organize mailboxes and provide:
- Inbox namespace: Standard inbox with special-use folders (Sent, Drafts, Trash)
- Shared namespaces: For shared mailboxes between users
- Public namespaces: For public folders accessible to all users
Namespaces allow different folder layouts, prefixes, and ACLs for different purposes.
Quick Reference
Section titled “Quick Reference”Essential Commands
Section titled “Essential Commands”# Test configurationdovecot -n
# Test authenticationdoveadm auth test user@example.com password
# List mailboxesdoveadm mailbox list -u user@example.com
# Check quotadoveadm quota get -u user@example.com
# Force re-logindoveadm kick user@example.com
# View connectionsdoveadm connection list
# Restart servicesudo systemctl restart dovecotDefault Ports
Section titled “Default Ports”| Service | Plain | SSL/TLS |
|---|---|---|
| IMAP | 143 | 993 |
| POP3 | 110 | 995 |
| LMTP | 24 | - |
| ManageSieve | 4190 | - |
Configuration Files
Section titled “Configuration Files”| File | Purpose |
|---|---|
| dovetcot.conf | Main configuration |
| 10-auth.conf | Authentication settings |
| 10-mail.conf | Mail storage settings |
| 10-ssl.conf | SSL/TLS settings |
| 10-master.conf | Service/process settings |
| 10-logging.conf | Logging settings |
| 90-quota.conf | Quota plugin |
| 90-sieve.conf | Sieve plugin |
| 90-acl.conf | ACL plugin |
Summary
Section titled “Summary”In this chapter, you learned:
- ✅ Dovecot architecture and protocol comparison
- ✅ Installation across different Linux distributions
- ✅ Core configuration (auth, mail, SSL)
- ✅ Advanced features (quota, sieve, ACL, replication)
- ✅ Database integration (MySQL, PostgreSQL, LDAP)
- ✅ Management and administration commands
- ✅ Troubleshooting common issues
- ✅ Production configuration examples
- ✅ Security hardening best practices
- ✅ Interview questions and answers
Next Chapter
Section titled “Next Chapter”Last Updated: February 2026