--- title: "How to Configure Dovecot IMAP and POP3 on Ubuntu 24.04" description: "Install Dovecot on Ubuntu 24.04 with Postfix to serve IMAP and POP3 over TLS, enable SMTP authentication on port 587 and block brute-force logins with Fail2ban." category: "Email Server" language: en source: https://cubepath.com/docs/email-server/dovecot-configuration-for-imap-pop3 updated: 2026-09-25 --- # How to Configure Dovecot IMAP and POP3 on Ubuntu 24.04 Dovecot is an IMAP and POP3 server: it gives mail clients such as Thunderbird, Outlook and phone mail apps access to the mailboxes that Postfix fills. It also provides the authentication service that Postfix uses to let those clients send mail through the server. In this tutorial you will add Dovecot to an existing Postfix server on Ubuntu 24.04, serve IMAP on port 993 and POP3 on port 995 with a Let's Encrypt certificate, and enable authenticated sending on port 587. ## Prerequisites To follow this tutorial you need: - A server running Ubuntu 24.04 LTS with Postfix already receiving mail for `your_domain`, configured as in the guide "How to Set Up a Postfix Mail Server on Ubuntu 24.04". In particular: - Postfix delivers to `Maildir/` in each user's home directory (`home_mailbox = Maildir/`). - A Let's Encrypt certificate exists in `/etc/letsencrypt/live/mail.your_domain/`. - UFW is enabled with SSH allowed. - A non-root user with `sudo` privileges. - A Linux user whose mailbox you will read, called `your_user` in this guide. Each mail account in this setup is a regular system user with a password; if you need mail accounts that are not Linux users, follow the Postfix and Dovecot virtual mailbox guide instead. ## Step 1 - Installing Dovecot Install the Dovecot core together with the IMAP and POP3 servers: ```bash sudo apt update sudo apt install dovecot-core dovecot-imapd dovecot-pop3d ``` The packages enable the `imap` and `pop3` protocols automatically and start the service. `dovecot --version` should report a 2.3 release, which is what the configuration in this guide is written for. Check the service state: ```bash sudo systemctl status dovecot --no-pager ``` ```output ● dovecot.service - Dovecot IMAP/POP3 email server Loaded: loaded (/usr/lib/systemd/system/dovecot.service; enabled; preset: enabled) Active: active (running) since ... ``` Dovecot's configuration is split into small files under `/etc/dovecot/conf.d/`, included by `/etc/dovecot/dovecot.conf`. You only need to change a few of them. ## Step 2 - Pointing Dovecot at the Maildir By default Ubuntu configures Dovecot to read mbox files in `/var/mail`. Postfix delivers to `~/Maildir`, so the two must agree. Open the mail settings: ```bash sudo nano /etc/dovecot/conf.d/10-mail.conf ``` Find the `mail_location` line and change it to: ```text mail_location = maildir:~/Maildir ``` Next, make sure every account gets the standard folders so mail clients store sent mail and drafts in the same place. Open the mailbox definitions: ```bash sudo nano /etc/dovecot/conf.d/15-mailboxes.conf ``` Add `auto = subscribe` to the `Drafts`, `Junk`, `Trash` and `Sent` mailboxes so they are created and subscribed automatically: ```text namespace inbox { mailbox Drafts { auto = subscribe special_use = \Drafts } mailbox Junk { auto = subscribe special_use = \Junk } mailbox Trash { auto = subscribe special_use = \Trash } mailbox Sent { auto = subscribe special_use = \Sent } mailbox "Sent Messages" { special_use = \Sent } } ``` Leave the rest of the file unchanged. ## Step 3 - Configuring authentication Dovecot authenticates system users through PAM by default (`!include auth-system.conf.ext` in `10-auth.conf`), which is what this setup needs. Two changes make it work well with mail clients. Open the authentication settings: ```bash sudo nano /etc/dovecot/conf.d/10-auth.conf ``` Set these values: ```text disable_plaintext_auth = yes auth_username_format = %Ln auth_mechanisms = plain login ``` - `disable_plaintext_auth = yes` refuses passwords on unencrypted connections. It is the default, but keep it explicit. - `auth_username_format = %Ln` lowercases the login and strips the domain, so a user can log in as `your_user@your_domain` or as `your_user`. Many clients fill in the full email address by default. - `auth_mechanisms = plain login` adds the `LOGIN` mechanism that older Outlook versions use. Both send the password in clear text inside the TLS connection, which is why TLS is required in the next step. ## Step 4 - Enabling TLS with the Let's Encrypt certificate Open the SSL settings: ```bash sudo nano /etc/dovecot/conf.d/10-ssl.conf ``` Replace the `ssl`, `ssl_cert` and `ssl_key` lines and set the minimum protocol: ```text ssl = required ssl_cert = QUIT <- 221 2.0.0 Bye ``` ## Step 8 - Protecting logins with Fail2ban A public IMAP and SMTP server receives password-guessing attempts within hours. Fail2ban reads the mail log and temporarily bans addresses with repeated failures. Install it: ```bash sudo apt install fail2ban ``` Enable the built-in jails for Dovecot and Postfix authentication in a local file, which package updates do not overwrite: ```bash sudo nano /etc/fail2ban/jail.d/mail.local ``` ```ini [dovecot] enabled = true [postfix-sasl] enabled = true ``` Restart Fail2ban and check the jails: ```bash sudo systemctl restart fail2ban sudo fail2ban-client status ``` ```output Status |- Number of jail: 3 `- Jail list: dovecot, postfix-sasl, sshd ``` `sudo fail2ban-client status dovecot` shows the currently banned addresses. ## Step 9 - Configuring a mail client Use these settings in Thunderbird, Outlook or a phone mail app: | Setting | Value | |---|---| | Username | `your_user@your_domain` (or `your_user`) | | Incoming server (IMAP) | `mail.your_domain`, port `993`, SSL/TLS, normal password | | Incoming server (POP3) | `mail.your_domain`, port `995`, SSL/TLS, normal password | | Outgoing server (SMTP) | `mail.your_domain`, port `587`, STARTTLS, normal password | Choose IMAP unless you specifically want messages downloaded and removed from the server. IMAP keeps mail and folders on the server, so every device sees the same state. ## Troubleshooting - **`auth failed` for a correct password**: check `sudo grep 'auth' /var/log/mail.log | tail`. A `pam_authenticate() failed` message means the password is wrong or the account is locked. Test directly with `sudo doveadm auth test your_user`. - **`Plaintext authentication disallowed on non-secure connection`**: the client connected to 143 or 110 without STARTTLS. Switch it to port 993 or 995 with SSL/TLS. - **Login works but the mailbox is empty**: Dovecot and Postfix disagree on the location. `postconf home_mailbox` must say `Maildir/` and `doveconf mail_location` must say `maildir:~/Maildir`. - **`SASL authentication failure: cannot connect to Dovecot auth server`**: the socket is missing or has the wrong owner. Check `/var/spool/postfix/private/auth` as in Step 7 and restart Dovecot. - **Clients warn about the certificate**: the client must use `mail.your_domain`, the name on the certificate, not the IP address or another hostname. ## Conclusion Your server now serves IMAP and POP3 over TLS, lets users send authenticated mail on port 587, and bans addresses that guess passwords. Every mail account is a Linux user, which works well for a few people. To host several domains or mailboxes that are not system accounts, move to virtual mailboxes delivered by Dovecot LMTP, and consider adding quotas and server-side filtering with Sieve (`dovecot-sieve`).