Dovecot

Dovecot is an open source IMAP and POP3 server for Linux/UNIX-like systems, written primarily with security in mind. Dovecot primarily aims to be a lightweight, fast and easy to set up open source mailserver. For more detailed information, please see the official Dovecot Wiki.

This article describes how to set up Dovecot for personal or small office use.

Installation

Install the dovecot package.

Configuration

Assumptions

  • Each mail account served by Dovecot, has a local user account defined on the server.
  • The server uses PAM to authenticate the user against the local user database (/etc/passwd).
  • TLS is used to encrypt the authentication password.
  • The common Maildir format is used to store the mail in the user's home directory.
  • A MDA has already been set up to deliver mail to the local users.

Create the TLS certificate

Warning: If you deploy TLS, be sure to follow weakdh.org's guide to prevent vulnerabilities. ssl_min_protocol defaults to TLSv1. For more information see Server-side TLS.

To obtain a certificate, see OpenSSL#Usage.

Alternatively you can generate the certificate using a script that comes with the dovecot package:

  1. Copy the example configuration: as the root user.
  2. Edit to configure the certificate.
  3. Execute /usr/lib/dovecot/mkcert.sh as the root user to generate the certificate.

The certificate/key pair is created as and .

Run and then trust extract-compat as the root user whenever you have changed your certificate.

Dovecot configuration

  • Create the dovecot configuration folder .
  • Copy the dovecot.conf and configuration files from to :
# mkdir /etc/dovecot
# cp /usr/share/doc/dovecot/example-config/dovecot.conf /etc/dovecot/dovecot.conf
# cp -r /usr/share/doc/dovecot/example-config/conf.d /etc/dovecot

pacman by default some containers is configured not to extract the doc directories to packages. Please edit /etc/pacman.conf to prevent this.

The default configuration is ok for most systems, but make sure to read through the configuration files to see what options are available. See the quick configuration guide and dovecot configuration for more instructions.

By default dovecot will try to detect what mail storage system is in use on the system. To use the Maildir format edit to set .

Generate DH parameters

To generate a new DH parameters file (this will take very long):

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

then add the file to

ssl_dh = </etc/dovecot/dh.pem

PAM Authentication with LDAP

  • If you are using an OpenLDAP server for authentication instead, be sure to be able to login with your LDAP users first, as described in LDAP authentication.

You can then write the following in remembering that the entries order is very important: In this way both LDAP and system users have their mailbox.

  • Edit /etc/dovecot/conf.d/auth-system.conf by changing the directive, like this:

By using the module and by adding the part in the directive, if an LDAP user logs in for the first time the corresponding home directory will be automatically created.

Sieve

Sieve is a programming language that can be used to create filters for email on mail server.

Sieve Interpreter Plugin

This facilitates the actual Sieve filtering upon delivery.

  • Install pigeonhole.
  • Depending on your usage, add to in
    • and/or
Note: Nowadays it is recommended to use LMTP instead of LDA. Nevertheless the Dovecot LDA can still be used for small mailservers. More information can be found in the Dovecot Wiki.
Example: SpamAssassin - move spam to "Junk" folder
  • Add spamtest configuration
/etc/dovecot/conf.d/90-sieve.conf
plugin {
  sieve_extensions = +spamtest +spamtestplus

  sieve_spamtest_status_type = score
  sieve_spamtest_status_header = \ 
    X-Spam_score: (-?[[:digit:]]+\.[[:digit:]]).* 
  sieve_spamtest_max_value = 5.0 

  sieve_before = /var/lib/dovecot/sieve/global_sieves/move_to_spam_folder.sieve
}

Note: This tests for "X-Spam_score" (which is the spam header format in default Exim configuration). Your header might look different, ie "X-Spam-Score".

  • Create sieve script:
  • To compile sieve, execute in shell and make sure the and the resulting move_to_spam_folder.svbin files are world readable.

ManageSieve Server

This implements the ManageSieve protocol through which users can remotely manage Sieve scripts on the server.

  • Follow the steps in #Sieve Interpreter Plugin above.
  • Add to in dovecot.conf
  • Add minimal
  • Restart . The managesieve daemon will listen on port 4190 by default.

By default Dovecot does not index the full message content, which will result in slow response times for queries for bigger mailboxes. There is a number of FTS backends Dovecot can be hooked up to.

Dovecot needs a plugin for the chosen search backend. The solr plugin is included in dovecot but solr itself is not the easiest to set up. There are packages for Xapian () and Elasticsearch ().

Starting the server

Start/enable .

Tips and tricks

Generate hashes with non-default hash functions:

$ doveadm pw -s SHA512-CRYPT -p "password"

Ensure that the column in the database is large enough. A warning will be emitted if it is too small.

Remember to set the password password scheme:

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.