Dovecot (Ubuntu 16.04)

Aus Tutorials
Zur Navigation springen Zur Suche springen

Installation

sudo apt-get install -y dovecot-core dovecot-imapd dovecot-pop3d dovecot-mysql dovecot-lmtpd

Virtuellen Benutzer anlegen

sudo addgroup --system --no-create-home --disabled-login --gid 126 vmail
sudo adduser --system --no-create-home --disabled-login --uid 126 --ingroup vmail vmail

Konfiguration

SSL Zertifikat

Hilfe zu Erstellung eines SSL-Zertifikates siehe SSL Zertifikat


Erstelltes Zertifikat in der Datei /etc/dovecot/conf.d/10-ssl.conf eintragen.

sudo vi /etc/dovecot/conf.d/10-ssl.conf
ssl = required
ssl_cert = </etc/ssl/certs/dovecot.crt
ssl_key = </etc/ssl/private/apache.key

Key und Zeritikat müssen für den Benutzer vmail lesbar sein:

sudo chmod a+r /etc/ssl/certs/dovecot.crt
sudo chmod a+r /etc/ssl/private/apache.key

Speicherort der Mails

Für die beschriebene Installation werden virtuelle Benutzer verwendet. Virtuelle Benutzer sind Benutzer, die sich nicht am System anmelden können.

Zuerst erstellen wir ein Grundverzeichnis, das dem Benutzer vmail gehört. Hier werden später in den entsprechenden Unterverzeichnissen die Mails einsortiert.

sudo mkdir /var/vmail/
sudo chown vmail:vmail /var/vmail/

Das Mailverzeichnis wird in der Datei /etc/dovecot/conf.d/10-mail.conf eingetragen:

sudo vi /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:/var/vmail/%d/%n
mail_privileged_group = vmail
# 126 = uid of user vmail
first_valid_uid = 126

Weiters wird hier noch das empfohlene Format maildir verwendet, was durch die Voranstellung von maildir: vor dem Pfad gekennzeichnet wird.

%d wird dann im laufenden Betrieb durch die Damain und %n durch den Benutzernamen ersetzt.

Benutzer Authentifizierung

Anlegen eines Benutzergrundverzeichnisses, das dem Benutzer vmail gehört (Benutzer mail muss darauf auch Schreibrechte haben - daher zur Gruppe hinzufügen)

sudo mkdir /home/vmail/
sudo chown vmail:vmail /home/vmail/

Datei /etc/dovecot/conf.d/10-auth.conf:

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

# Folgende Zeile auskommentieren:
# !include auth-system.conf.ext

# Folgende Zeile einkommentieren:
!include auth-sql.conf.ext

In der Datei /etc/dovecot/conf.d/auth-sql.conf.ext folgende Zeile ausbessern / einkommentieren:

sudo vi /etc/dovecot/conf.d/auth-sql.conf.ext
# Database driver: mysql, pgsql, sqlite
userdb {
  driver = static
  args = uid=vmail gid=vmail home=/home/vmail/%u
}

Datei /etc/dovecot/dovecot-sql.conf.ext:

sudo vi /etc/dovecot/dovecot-sql.conf.ext

'126' is 'gid' and 'uid' of user 'vmail'

# Database driver: mysql, pgsql, sqlite
driver = mysql

connect = host=localhost dbname=postfix user=postfix password=<password>

default_pass_scheme = SHA512-CRYPT

password_query = SELECT local_part, domain, password FROM mailbox WHERE local_part = '%n' AND domain = '%d'

user_query = SELECT ('126') as 'uid', ('126') as 'gid'

SASL / LMTP

Datei /etc/dovecot/conf.d/10-master.conf:

sudo vi /etc/dovecot/conf.d/10-master.conf
service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
    mode = 0660
    group = postfix
    user = postfix
  }

  user = vmail
}

service auth {
  unix_listener auth-userdb {
    mode = 0666
    user = vmail
    group = vmail
  }

  # Postfix smtp-auth
  unix_listener /var/spool/postfix/private/auth {
    mode = 0666
    user = postfix
    group = postfix
  }
}

Mail-Ordner automatisch erstellen

Standardmäßig werden Ordner nict automatisch angelegt. Dazu muss die Datei /etc/dovecot/conf.d/15-mailboxes.conf angepaßt werden:

sudo vi /etc/dovecot/conf.d/15-mailboxes.conf

Bei allen Ordnern auto=create hinzufügen:

namespace inbox {
  # These mailboxes are widely used and could perhaps be created automatically:
  mailbox Drafts {
    special_use = \Drafts
    auto=create
  }
  mailbox Junk {
    special_use = \Junk
    auto=create
  }
  mailbox Trash {
    special_use = \Trash
    auto=create
  }

  # For \Sent mailboxes there are two widely used names. We'll mark both of
  # them as \Sent. User typically deletes one of them if duplicates are created.
  mailbox Sent {
    special_use = \Sent
    auto=create
  }
  mailbox "Sent Messages" {
    special_use = \Sent
    auto=create
  }
}

Allgemein

Datei /etc/dovecot/dovecot.conf:

sudo vi /etc/dovecot/dovecot.conf
# Enable installed protocols
!include_try /usr/share/dovecot/protocols.d/*.protocol

listen = *, ::

base_dir = /var/run/dovecot/

# Greeting message for clients
login_greeting = Dovecot ready.

!include conf.d/*.conf
!include_try local.conf

postmaster_address = <valid mail address>

# PassDB SQL
passdb {
    driver = sql
    args = /etc/dovecot/dovecot-sql.conf.ext
}

Dovecot neustarten

sudo service dovecot restart

Probleme

[private/dovecot-lmtp]: No such file or directory)

Das Paket dovecot-lmtpd war nicht installiert:

sudo apt-get install dovecot-lmtpd

Links

https://wiki.ubuntuusers.de/Dovecot_2/


Weiter zu Postfix

Zurück zu Mailserver einrichten