Exim

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen

Mailserver-Installation mit Exim4 und Dovecot

Diese Anleitung beschreibt die vollständige Einrichtung eines Mailservers unter Debian. Es wird Exim4 als MTA und Dovecot als MDA verwendet, inklusive TLS-Verschlüsselung und Maildir-Zustellung.

Vorbereitung

Bestehende Dienste entfernen

Um eine saubere Basis zu schaffen, werden alle alten Mail-Komponenten und deren Konfigurationsdateien gelöscht.

systemctl stop postfix exim4 dovecot || true
apt purge -y postfix exim4 exim4-base exim4-config exim4-daemon-light exim4-daemon-heavy dovecot-core dovecot-imapd dovecot-lmtpd
apt autoremove -y
apt autoclean
rm -rf /etc/postfix /etc/exim4 /etc/dovecot /var/spool/postfix /var/spool/exim4

Verzeichnisse und Berechtigungen

Das Verzeichnis für die Kommunikation zwischen Exim und Dovecot (LMTP/Auth) sowie das Mail-Skelett für neue Benutzer werden vorbereitet.

mkdir -p /var/spool/exim4/private
chown Debian-exim:Debian-exim /var/spool/exim4/private
chmod 750 /var/spool/exim4/private

mkdir -p /etc/skel/Maildir/{cur,new,tmp}
grep -q MAILDIR /etc/skel/.bashrc || echo 'export MAIL=$HOME/Maildir' >> /etc/skel/.bashrc

Installation

Installation der notwendigen Pakete:

apt update
DEBIAN_FRONTEND=noninteractive apt install -y exim4 dovecot-core dovecot-imapd dovecot-lmtpd mailutils

Konfiguration

Exim4 Basis und Domain-Empfang

Damit Exim Mails für den Hostnamen UND die Domain annimmt, wird dc_other_hostnames entsprechend gesetzt.

FQDN=$(hostname -f)
DOM=$(hostname -d)

cat > /etc/exim4/update-exim4.conf.conf <<EOF
dc_eximconfig_configtype='internet'
dc_other_hostnames='$FQDN:$DOM'
dc_local_interfaces='0.0.0.0'
dc_readhost=''
dc_relay_domains=''
dc_minimaldns='false'
dc_relay_nets=''
dc_smarthost=''
dc_use_split_config='true'
dc_hide_mailname=''
dc_mailname_in_oh='true'
dc_localdelivery='maildir_home'
EOF

Exim4 TLS und Ports

Konfiguration der SSL-Zertifikate und Aktivierung von SMTPS auf Port 465.

cat <<EOF > /etc/exim4/conf.d/main/03_exim4-config_tlsoptions
tls_certificate = /etc/ssl/own.crt
tls_privatekey  = /etc/ssl/own.key
EOF

cat <<EOF > /etc/exim4/conf.d/main/02_smtps
daemon_smtp_ports = 25 : 465
tls_on_connect_ports = 465
EOF

update-exim4.conf
systemctl restart exim4

Dovecot

Mail-Speicher

cat > /etc/dovecot/conf.d/10-mail.conf <<EOF
mail_driver = maildir
mail_home = /home/%{user | username}
mail_path = %{home}/Maildir
EOF

SSL/TLS

cat > /etc/dovecot/conf.d/10-ssl.conf <<EOF
ssl = yes
ssl_server_cert_file = /etc/ssl/own.crt
ssl_server_key_file = /etc/ssl/own.key
ssl_min_protocol = TLSv1.2
EOF

Master-Dienste (Socket-Anbindung)

Definition der Sockets für LMTP und Auth-Abfragen durch Exim.

cat > /etc/dovecot/conf.d/10-master.conf <<EOF
service imap-login {
  inet_listener imap {
  }
  inet_listener imaps {
  }
}

service lmtp {
  unix_listener /var/spool/exim4/private/dovecot-lmtp {
    mode = 0600
    user = Debian-exim
    group = Debian-exim
  }
}

service auth {
  unix_listener /var/spool/exim4/private/auth {
    mode = 0660
    user = Debian-exim
    group = Debian-exim
  }
}
EOF

Abschluss

Dienste neu starten, um alle Änderungen zu übernehmen:

systemctl restart exim4
systemctl restart dovecot