第 1 章 Configuring and maintaining a Dovecot IMAP and POP3 server


Dovecot is a high-performance mail delivery agent (MDA) with a focus on security. You can use IMAP or POP3-compatible email clients to connect to a Dovecot server and read or download emails.

Key features of Dovecot:

  • The design and implementation focuses on security
  • Two-way replication support for high availability to improve the performance in large environments
  • Supports the high-performance dbox mailbox format, but also mbox and Maildir for compatibility reasons
  • Self-healing features, such as fixing broken index files
  • Compliance with the IMAP standards
  • Workaround support to bypass bugs in IMAP and POP3 clients

1.1. Setting up a Dovecot server with PAM authentication

Dovecot supports the Name Service Switch (NSS) interface as a user database and the Pluggable Authentication Modules (PAM) framework as an authentication backend. With this configuration, Dovecot can provide services to users who are available locally on the server through NSS.

Use PAM authentication if accounts:

  • Are defined locally in the /etc/passwd file
  • Are stored in a remote database but they are available locally through the System Security Services Daemon (SSSD) or other NSS plugins.

1.1.1. Installing Dovecot

The dovecot package provides:

  • The dovecot service and the utilities to maintain it
  • Services that Dovecot starts on demand, such as for authentication
  • Plugins, such as server-side mail filtering
  • Configuration files in the /etc/dovecot/ directory
  • Documentation in the /usr/share/doc/dovecot/ directory

Procedure

  • Install the dovecot package:

    # dnf install dovecot
    注意

    If Dovecot is already installed and you require clean configuration files, rename or remove the /etc/dovecot/ directory. Afterwards, reinstall the package. Without removing the configuration files, the dnf reinstall dovecot command does not reset the configuration files in /etc/dovecot/.

1.1.2. Configuring TLS encryption on a Dovecot server

Dovecot provides a secure default configuration. For example, TLS is enabled by default to transmit credentials and data encrypted over networks. To configure TLS on a Dovecot server, you only need to set the paths to the certificate and private key files. Additionally, you can increase the security of TLS connections by generating and by using Diffie-Hellman parameters to provide perfect forward secrecy (PFS).

Prerequisites

  • Dovecot is installed.
  • The following files have been copied to the listed locations on the server:

    • The server certificate: /etc/pki/dovecot/certs/server.example.com.crt
    • The private key: /etc/pki/dovecot/private/server.example.com.key
    • The Certificate Authority (CA) certificate: /etc/pki/dovecot/certs/ca.crt
  • The hostname in the Subject DN field of the server certificate matches the server’s Fully-qualified Domain Name (FQDN).
  • If the FIPS mode is enabled, clients must either support the Extended Master Secret (EMS) extension or use TLS 1.3. TLS 1.2 connections without EMS fail. For more information, see the Red Hat Knowledgebase solution TLS extension "Extended Master Secret" enforced.

Procedure

  1. Set secure permissions on the private key file:

    # chown root:root /etc/pki/dovecot/private/server.example.com.key
    # chmod 600 /etc/pki/dovecot/private/server.example.com.key
  2. Generate a file with Diffie-Hellman parameters:

    # openssl dhparam -out /etc/dovecot/dh.pem 4096

    Depending on the hardware and entropy on the server, generating Diffie-Hellman parameters with 4096 bits can take several minutes.

  3. Set the paths to the certificate and private key files in the /etc/dovecot/conf.d/10-ssl.conf file:

    1. Update the ssl_cert and ssl_key parameters, and set them to use the paths of the server’s certificate and private key:

      ssl_cert = </etc/pki/dovecot/certs/server.example.com.crt
      ssl_key = </etc/pki/dovecot/private/server.example.com.key
    2. Uncomment the ssl_ca parameter, and set it to use the path to the CA certificate:

      ssl_ca = </etc/pki/dovecot/certs/ca.crt
    3. Uncomment the ssl_dh parameter, and set it to use the path to the Diffie-Hellman parameters file:

      ssl_dh = </etc/dovecot/dh.pem
    重要

    To ensure that Dovecot reads the value of a parameter from a file, the path must start with a leading < character.

1.1.3. Preparing Dovecot to use virtual users

By default, Dovecot performs many actions on the file system as the user who uses the service. However, configuring the Dovecot back end to use one local user to perform these actions has several benefits:

  • Dovecot performs file system actions as a specific local user instead of using the user’s ID (UID).
  • Users do not need to be available locally on the server.
  • You can store all mailboxes and user-specific files in one root directory.
  • Users do not require a UID and group ID (GID), which reduces administration efforts.
  • Users who have access to the file system on the server cannot compromise their mailboxes or indexes because they cannot access these files.
  • Setting up replication is easier.

Prerequisites

  • Dovecot is installed.

Procedure

  1. Create the vmail user:

    # useradd --home-dir /var/mail/ --shell /usr/sbin/nologin vmail

    Dovecot will later use this user to manage the mailboxes. For security reasons, do not use the dovecot or dovenull system users for this purpose.

  2. If you use a different path than /var/mail/, set the mail_spool_t SELinux context on it, for example:

    # semanage fcontext -a -t mail_spool_t "<path>(/.)?"*
    # restorecon -Rv <path>
  3. Grant write permissions on /var/mail/ only to the vmail user:

    # chown vmail:vmail /var/mail/
    # chmod 700 /var/mail/
  4. Uncomment the mail_location parameter in the /etc/dovecot/conf.d/10-mail.conf file, and set it to the mailbox format and location:

    mail_location = sdbox:/var/mail/%n/

    With this setting:

    • Dovecot uses the high-performant dbox mailbox format in single mode. In this mode, the service stores each mail in a separate file, similar to the maildir format.
    • Dovecot resolves the %n variable in the path to the username. This is required to ensure that each user has a separate directory for its mailbox.

1.1.4. Using PAM as the Dovecot authentication backend

By default, Dovecot uses the Name Service Switch (NSS) interface as the user database and the Pluggable Authentication Modules (PAM) framework as the authentication backend.

Customize the settings to adapt Dovecot to your environment and to simplify administration by using the virtual users feature.

Prerequisites

  • Dovecot is installed.
  • The virtual users feature is configured.

Procedure

  1. Update the first_valid_uid parameter in the /etc/dovecot/conf.d/10-mail.conf file to define the lowest user ID (UID) that can authenticate to Dovecot:

    first_valid_uid = 1000

    By default, users with a UID greater than or equal to 1000 can authenticate. If required, you can also set the last_valid_uid parameter to define the highest UID that Dovecot allows to log in.

  2. In the /etc/dovecot/conf.d/auth-system.conf.ext file, add the override_fields parameter to the userdb section as follows:

    userdb {
      driver = passwd
      override_fields = uid=vmail gid=vmail home=/var/mail/%n/
    }

    Due to the fixed values, Dovecot does not query these settings from the /etc/passwd file. As a result, the home directory defined in /etc/passwd does not need to exist.

1.1.5. Completing the Dovecot configuration

Once you have installed and configured Dovecot, open the required ports in the firewalld service, and enable and start the service. Afterwards, you can test the server.

Prerequisites

  • The following has been configured in Dovecot:

    • TLS encryption
    • An authentication backend
  • Clients trust the Certificate Authority (CA) certificate.

Procedure

  1. If you want to provide only an IMAP or POP3 service to users, uncomment the protocols parameter in the /etc/dovecot/dovecot.conf file, and set it to the required protocols. For example, if you do not require POP3, set:

    protocols = imap lmtp

    By default, the imap, pop3, and lmtp protocols are enabled.

  2. Open the ports in the local firewall. For example, to open the ports for the IMAPS, IMAP, POP3S, and POP3 protocols, enter:

    # firewall-cmd --permanent --add-service=imaps --add-service=imap --add-service=pop3s --add-service=pop3
    # firewall-cmd --reload
  3. Enable and start the dovecot service:

    # systemctl enable --now dovecot

Verification

  1. Use a mail client, such as Mozilla Thunderbird, to connect to Dovecot and read emails. The settings for the mail client depend on the protocol you want to use:

    Expand
    表 1.1. Connection settings to the Dovecot server
    ProtocolPortConnection securityAuthentication method

    IMAP

    143

    STARTTLS

    PLAIN[a]

    IMAPS

    993

    SSL/TLS

    PLAIN[a]

    POP3

    110

    STARTTLS

    PLAIN[a]

    POP3S

    995

    SSL/TLS

    PLAIN[a]

    [a] The client transmits data encrypted through the TLS connection. Consequently, credentials are not disclosed.

    Note that this table does not list settings for unencrypted connections because, by default, Dovecot does not accept plain text authentication on connections without TLS.

  2. Display configuration settings with non-default values:

    # doveconf -n
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部