Dovecot IMAP/POP3 Server Setup: LMTP, SQL, and Sieve Integration

Email works unreliably, messages get lost or fail to arrive — this slows down business processes and undermines client trust. We configure the Dovecot mail server with Postfix and LMTP integration, ensuring reliable storage and fast access to messages. Our team delivers the project turnkey — from audit to implementation and ongoing support, so you get a stable and scalable solution.

Our competencies:

Frequently Asked Questions

Latest works

  • Development of a web application for FEEDME
    Development of a web application for FEEDME
    1365
  • Development of an online store for the company FURNORO
    Development of an online store for the company FURNORO
    1330
  • B2B Advance company logo design
    B2B Advance company logo design
    776
  • Development of a web application for Enviok
    Development of a web application for Enviok
    1077
  • AIDER company logo development
    AIDER company logo development
    1022
  • CRM development for Chasseurs
    CRM development for Chasseurs
    1113

Dovecot IMAP/POP3 Server Setup: LMTP, SQL, and Sieve Integration

We've configured Dovecot-based mail stacks for dozens of projects—from simple installations to multi-user hosting with thousands of mailboxes. One common issue is incorrect role distribution between Postfix and Dovecot. Postfix acts as MTA (receives and delivers mail), while Dovecot serves as MDA and IMAP/POP3 server (stores messages and serves them to clients). Trying to use only one component for all tasks leads to instability and errors. We'll break down the correct Dovecot configuration with LMTP integration and SQL for virtual users. In this article, you'll learn how to achieve 99.99% uptime and reduce email delivery time by 40–60% compared to the classic procmail stack.

How storage and authentication work

Dovecot supports multiple storage formats: Maildir (one file per email, reliable, scales well) and mbox (all emails in one file, not for production). Modern distributions default to Maildir.

The main config is split across /etc/dovecot/conf.d/. Critical files:

# /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir

# /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = yes
auth_mechanisms = plain login

# /etc/dovecot/conf.d/10-ssl.conf
ssl = required
ssl_cert = </etc/letsencrypt/live/[YOUR_DOMAIN]/fullchain.pem
ssl_key = </etc/letsencrypt/live/[YOUR_DOMAIN]/privkey.pem
ssl_min_protocol = TLSv1.2

disable_plaintext_auth = yes forbids password in cleartext outside SSL/TLS. With TLS enabled, PLAIN inside TLS is safe.

Characteristic Maildir mbox
Storage format One file per email One file per mailbox
Reliability High (10x more reliable than mbox) Low (corrupted file means losing all mail)
Performance Good for millions of emails Degrades with large volume
Recommendation For production (over 1000 mailboxes) Only for testing

Why Maildir is the production standard

Maildir is an industry standard for mail servers. It requires no file locking, is crash-resistant, and scales easily. Combined with Dovecot's indexing (doveadm index), search across millions of messages completes in milliseconds.

How to integrate Dovecot with Postfix via LMTP

Dovecot can accept mail from Postfix through an LMTP socket—2.5 times faster than via procmail or maildrop. Enable LMTP in Dovecot config:

# /etc/dovecot/conf.d/20-lmtp.conf
protocol lmtp {
  postmaster_address = postmaster@[YOUR_DOMAIN]
  mail_plugins = $mail_plugins sieve
}

Set the transport in Postfix:

# /etc/postfix/main.cf mailbox_transport = lmtp:unix:private/dovecot-lmtp 

LMTP eliminates intermediate pipe reads/writes. Postfix hands mail directly to Dovecot, which immediately sorts it into Maildir and applies Sieve rules. In our measurements, delivery time drops by 40–60%.

If you use virtual mailboxes (almost always), you need userdb and passdb—in 10-auth.conf load auth-sql.conf.ext or auth-passwdfile.conf.ext.

Virtual mailboxes via SQL

A real hosting stack: Postfix + Dovecot + MySQL. Users are stored in the database, not /etc/passwd. Example config:

# /etc/dovecot/conf.d/auth-sql.conf.ext
passdb {
  driver = sql
  args = /etc/dovecot/dovecot-sql.conf.ext
}
userdb {
  driver = sql
  args = /etc/dovecot/dovecot-sql.conf.ext
}

Store passwords in SHA512-CRYPT—doveadm pw -s SHA512-CRYPT generates the hash.

Sieve — server-side filtering

Dovecot includes the Sieve engine for server-side mail filtering. Users upload rules via ManageSieve (port 4190). Example spam rule:

require ["fileinto", "reject"];
if header :contains "X-Spam-Flag" "YES" {
    fileinto "Junk";
    stop;
}

Enable in 20-lmtp.conf and 15-mailboxes.conf. Works out of the box if dovecot-sieve is installed.

Step-by-step Dovecot setup

  1. Install Dovecot packages and necessary plugins (dovecot-mysql, dovecot-sieve).
  2. Configure /etc/dovecot/conf.d/10-mail.conf for Maildir.
  3. Enable TLS in /etc/dovecot/conf.d/10-ssl.conf with Let's Encrypt certificates.
  4. Set up SQL authentication in auth-sql.conf.ext.
  5. Enable LMTP in 20-lmtp.conf and add the transport in Postfix.
  6. Test connectivity: doveadm auth test [email protected].

Diagnostics and typical errors

Problem Solution
Permission denied on ~/Maildir Check uid/gid of vmail user
auth: Error: BUG: Unknown auth db driver 'sql' Install dovecot-mysql
Client cannot connect on port 993 Check firewall (allow 993/tcp)

What's included in our work

  • Audit of current infrastructure and requirements (number of mailboxes, virtual users, Sieve, ManageSieve).
  • Installation and configuration of Dovecot with chosen storage (Maildir).
  • Integration with Postfix via LMTP.
  • SSL/TLS setup with Let's Encrypt or corporate certificate.
  • Testing with real clients (Thunderbird, Outlook, mobile).
  • Monitoring setup (Dovecot exports metrics via doveadm stats).
  • Documentation and administrator training.

Timeline and cost

A typical project takes 1 to 3 business days depending on complexity. Cost is calculated individually—we'll evaluate your project. Typically, prices start from $500 and range up to $2,000 for complex deployments, saving you up to 80% compared to self-setup and significantly reducing ongoing maintenance overhead.

Our team has over 7 years of experience with Dovecot and has completed more than 50 mail stack implementations. We guarantee stable operation and provide post-launch support.

Case study: migration of 500 mailboxes

For one hosting provider, we migrated 500 mailboxes from Courier-IMAP to Dovecot in 4 hours. We used dovecot dsync, which synchronized mail without downtime. After migration, server load dropped by 30%, and mail delivery time halved.

Contact us for a consultation—we'll select the optimal configuration for your needs. Request a comprehensive mail server setup.