Email & webmail

Set up Dovecot as an IMAP server with Postfix on Linux

Install Dovecot, store mail in Maildir, require TLS on IMAP 993, connect it to Postfix for local delivery (LMTP) and SMTP authentication, and test logins from a mail app.

AdvancedLinux VPS3 min read

Dovecot is the IMAP server that lets mail apps and webmail read mailboxes. Paired with Postfix it forms a complete self-hosted mail server: Postfix receives and sends, Dovecot stores and serves. This guide sets up Dovecot with system users, TLS and Postfix integration.

Before you start

  • A Linux VPS with Postfix already accepting mail for your domain (MX record pointing to the server, mydestination including your domain).
  • A TLS certificate for the mail hostname, for example from Let's Encrypt for mail.example.com.
  • Ports 25, 587 and 993 open.

Tip: Self-hosted email takes ongoing care. On MdmHost cPanel hosting, Dovecot and Exim are already configured and maintained for you.

Install Dovecot

  • Ubuntu/Debian: sudo apt install -y dovecot-imapd dovecot-lmtpd
  • AlmaLinux/Rocky: sudo dnf install -y dovecot && sudo systemctl enable dovecot

Settings are split across /etc/dovecot/conf.d/.

Configure mail storage

In 10-mail.conf:

mail_location = maildir:~/Maildir

Each user's mail is stored as files in ~/Maildir.

Require TLS and secure authentication

  1. In 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
  2. In 10-auth.conf:
    disable_plaintext_auth = yes
    auth_mechanisms = plain login
  3. In 10-master.conf, disable plain IMAP on 143 by setting its port = 0 inside inet_listener imap, and keep imaps on 993.

Deliver mail from Postfix via LMTP

  1. In 10-master.conf, expose LMTP to Postfix:
    service lmtp {
      unix_listener /var/spool/postfix/private/dovecot-lmtp {
        mode = 0600
        user = postfix
        group = postfix
      }
    }
  2. In Postfix's main.cf:
    mailbox_transport = lmtp:unix:private/dovecot-lmtp

Let Postfix authenticate users through Dovecot

  1. In Dovecot's 10-master.conf:
    service auth {
      unix_listener /var/spool/postfix/private/auth {
        mode = 0660
        user = postfix
        group = postfix
      }
    }
  2. In Postfix's master.cf, enable the submission service on port 587 with:
    submission inet n - y - - smtpd
      -o smtpd_tls_security_level=encrypt
      -o smtpd_sasl_auth_enable=yes
      -o smtpd_sasl_type=dovecot
      -o smtpd_sasl_path=private/auth
      -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
  3. Restart both: sudo systemctl restart dovecot postfix.

Test the server

  1. Check the config: doveconf -n.
  2. Test TLS on IMAP: openssl s_client -connect mail.example.com:993 – you should see the Dovecot greeting.
  3. Add the account in a mail app: IMAP mail.example.com port 993 SSL/TLS; SMTP port 587 STARTTLS; username is the Linux user.
  4. Send a message to the account and watch journalctl -u dovecot -f for a successful LMTP delivery.

Troubleshooting

  • Login fails: check journalctl -u dovecot; make sure the user exists and has a password.
  • Postfix "connect to private/dovecot-lmtp: No such file": the socket path or permissions in 10-master.conf do not match.
  • Certificate warnings in mail apps: the certificate does not cover the hostname clients use.
  • Mail delivered to /var/mail instead of Maildir: mailbox_transport is not set in Postfix.

FAQ: Dovecot IMAP server

Can I use virtual users instead of Linux accounts?

Yes. Dovecot supports password files and SQL databases for virtual mailboxes; it is more setup but scales better.

Should I enable POP3?

Only if users need it. IMAP keeps mail in sync across devices, which suits most people.

How do I add spam filtering?

Add Rspamd or SpamAssassin as a Postfix milter, and use Dovecot's Sieve plugin to file spam into a Junk folder.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.