Mail-Server-Einrichtung: Postfix und Dovecot
Vollständige Anleitung zur Einrichtung von Postfix MTA, Dovecot IMAP/POP3, SSL/TLS-Konfiguration, virtueller Domain-Unterstützung, Spam-Filterung und Docker Mail Server.
Inhaltsverzeichnis
Mail-Server-Einrichtung: Postfix und Dovecot
Die Einrichtung eines eigenen Mail-Servers gibt Ihnen volle Kontrolle über Ihre E-Mail-Kommunikation. Diese Anleitung behandelt Postfix MTA (Mail Transfer Agent), Dovecot IMAP/POP3-Server, SSL/TLS-Konfiguration, virtuelle Domain-Unterstützung und Docker Mail Server-Einrichtung.
Die Verwaltung eines Mail-Servers ist komplex und erfordert laufende Wartung. IP-Reputation, Spam-Filterung und Sicherheitsupdates müssen regelmäßig überwacht werden.
Voraussetzungen
DNS-Einträge
Erstellen Sie folgende DNS-Einträge vor der Einrichtung:
# A-Eintrag - Mail-Server-IP
mail.example.com A 185.x.x.x
# MX-Eintrag - Mail-Routing
example.com MX 10 mail.example.com
# SPF-Eintrag
example.com TXT "v=spf1 mx ip4:185.x.x.x -all"
# Reverse DNS (PTR) Eintrag
185.x.x.x PTR mail.example.com
Der PTR-Eintrag (Reverse DNS) kann über das REXE-Kundenpanel oder per Support-Anfrage eingerichtet werden. E-Mails ohne PTR-Eintrag können als Spam markiert werden.
Hostname-Einrichtung
sudo hostnamectl set-hostname mail.example.com
echo "185.x.x.x mail.example.com mail" | sudo tee -a /etc/hosts
hostname -f
Postfix-Installation (MTA)
sudo apt update
sudo apt install postfix postfix-mysql -y
# Wählen Sie "Internet Site" während der Installation
Grundkonfiguration
# /etc/postfix/main.cf
myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
mydestination = $myhostname, localhost.$mydomain, localhost
inet_interfaces = all
inet_protocols = ipv4
mynetworks = 127.0.0.0/8
home_mailbox = Maildir/
# TLS-Einstellungen
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.example.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mail.example.com/privkey.pem
smtpd_use_tls = yes
smtpd_tls_auth_only = yes
# SASL-Authentifizierung
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
# Einschränkungen
smtpd_recipient_restrictions =
permit_sasl_authenticated,
permit_mynetworks,
reject_unauth_destination,
reject_invalid_hostname,
reject_non_fqdn_hostname,
reject_non_fqdn_sender,
reject_unknown_sender_domain,
reject_rbl_client zen.spamhaus.org
message_size_limit = 52428800
Submission-Port (587)
# /etc/postfix/master.cf
submission inet n - y - - smtpd
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_tls_auth_only=yes
-o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
Dovecot-Installation (IMAP/POP3)
sudo apt install dovecot-core dovecot-imapd dovecot-pop3d dovecot-lmtpd -y
Konfiguration
# /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp
# /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir
# /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = yes
auth_mechanisms = plain login
# /etc/dovecot/conf.d/10-ssl.conf
ssl = required
ssl_cert = </etc/letsencrypt/live/mail.example.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.example.com/privkey.pem
ssl_min_protocol = TLSv1.2
# /etc/dovecot/conf.d/10-master.conf
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}
}
SSL/TLS-Zertifikat
sudo apt install certbot -y
sudo certbot certonly --standalone -d mail.example.com
Docker Mail Server (Alternative)
version: '3.8'
services:
mailserver:
image: ghcr.io/docker-mailserver/docker-mailserver:latest
container_name: mailserver
hostname: mail.example.com
ports:
- "25:25"
- "465:465"
- "587:587"
- "993:993"
volumes:
- ./docker-data/dms/mail-data/:/var/mail/
- ./docker-data/dms/mail-state/:/var/mail-state/
- ./docker-data/dms/mail-logs/:/var/log/mail/
- ./docker-data/dms/config/:/tmp/docker-mailserver/
- /etc/letsencrypt:/etc/letsencrypt:ro
environment:
- ENABLE_SPAMASSASSIN=1
- ENABLE_CLAMAV=1
- ENABLE_FAIL2BAN=1
- SSL_TYPE=letsencrypt
restart: always
docker exec -it mailserver setup email add user@example.com
docker exec -it mailserver setup config dkim
docker compose up -d
Spam-Filterung
sudo apt install spamassassin spamc -y
sudo systemctl enable spamassassin
sudo systemctl start spamassassin
Test und Überprüfung
sudo systemctl status postfix
sudo systemctl status dovecot
sudo ss -tlnp | grep -E '25|587|993|995'
echo "Test-Mail" | mail -s "Test" user@example.com
sudo tail -f /var/log/mail.log
openssl s_client -connect mail.example.com:587 -starttls smtp
openssl s_client -connect mail.example.com:993
Überprüfen Sie nach der Einrichtung Ihren Spam-Score auf mail-tester.com. Stellen Sie sicher, dass SPF, DKIM und DMARC korrekt konfiguriert sind.
Fazit
Die Einrichtung eines eigenen Mail-Servers bietet volle Kontrolle, erfordert aber regelmäßige Wartung. Die Kombination Postfix + Dovecot bietet eine zuverlässige Lösung, während Docker Mail Server eine einfachere Verwaltung ermöglicht.
Verwandte Artikel
E-Mail-Blacklist-Entfernung: Anleitung
Anleitung zur Blacklist-Prüfung, Delisting-Anträgen, Spamhaus/Barracuda/SORBS-Verfahren und IP-Reputationsmanagement.
SPF, DKIM und DMARC Konfigurationsanleitung
Vollständige Anleitung zur Konfiguration von SPF-Einträgen, DKIM-Signierung, DMARC-Richtlinien, DNS-Einträgen und Testtools zur Verbesserung der E-Mail-Zustellbarkeit und Sicherheit.