Postfix (Ubuntu 16.04)

Aus Tutorials
Zur Navigation springen Zur Suche springen

Noch in Bearbeitung


Installation

sudo apt-get install postfix postfix-mysql

Beim sich öffnenden Menü Keine Konfiguration auswählen.

Konfiguration

Eine neue Datei main.cf erstellen und mit folgenden Inhalt befüllen (<local domain> durch den entsprechenden Wert ersetzen):

sudo vi /etc/postfix/main.cf
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

append_dot_mydomain = no

readme_directory = no

mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mydestination =
mailbox_size_limit = 51200000
message_size_limit = 51200000
recipient_delimiter = localhost.$mydomain, localhost, mail.$mydomain
inet_interfaces = all
myorigin = <local domain>
myhostname = mail.<domain name>
inet_protocols = all

In der Datei master.cf folgende Zeile hinzufügen:

sudo vi /etc/postfix/master.cf
submission inet n       -       -       -       -       smtpd -v
  ...
  -o smtp_bind_address=<ip address>
  ...

SSL Zertifikat

Hilfe zu Erstellung eines SSL-Zertifikates siehe SSL Zertifikat

In der Datei /etc/postfix/main.cf folgende Zeilen hinzufügen:

sudo vi /etc/postfix/main.cf
##### TLS parameters ######
smtpd_tls_cert_file=/etc/ssl/certs/postfix.crt
smtpd_tls_key_file=/etc/ssl/private/apache.key
smtpd_use_tls=yes
smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

SASL Auth und Submission aktivieren

Postfix soll bei Dovecot per SASL Authentifizierung nachfragen, ob für die akutellen Benutzer/Passwort-Kombination das Senden/Empfangen erlaubt ist.

Dazu in der Datei /etc/postfix/main.cf folgende Zeilen hinzufügen:

sudo vi /etc/postfix/main.cf
###### SASL Auth ######
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes

In der Datei /etc/postfix/master.cf den submission-Block folgendermassen anpassen bzw. ersetzen:

sudo vi /etc/postfix/master.cf
submission inet n       -       -       -       -       smtpd -v
  -o syslog_name=postfix/submission
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_type=dovecot
  -o smtpd_sasl_path=private/auth
  -o smtpd_sasl_security_options=noanonymous
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject

LMTP aktivieren

In der Datei /etc/postfix/main.cf Zeilen hinzufügen:

sudo vi /etc/postfix/main.cf
###### Use Dovecot LMTP Service to deliver Mails to Dovecot ######
virtual_transport = lmtp:unix:private/dovecot-lmtp

Relay Einstellungen

Mails sollen nur weitergeleited werden, falls der Sender der Server selbst ist oder der Benutzer in die Benutzerdatenbank von Dovecot eingetragen ist.

Dazu in der Datei /etc/postfix/main.cf folgende Zeilen hinzufügen:

sudo vi /etc/postfix/main.cf 
##### Only allow mail transport if client is authenticated or in own network (PHP Scripts, ...) ######
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

Datenbankanbindung

Hauptdatei

In der Datei /etc/postfix/main.cf die Datenbank-Konfigurations-Dateien eintragen:

###### MySQL Connection ######

virtual_alias_maps = proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf,
    proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_maps.cf,
    proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/sql/mysql_virtual_mailbox_maps.cf,
    proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf
virtual_mailbox_domains = proxy:mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cf
local_recipient_maps = $virtual_mailbox_maps

MySQL-Dateien

Verzeichnis für Konfiguartionsdateien erstellen:

sudo mkdir /etc/postfix/sql

Die folgenden Dateien können manuell als auch automatisch erstellt werden.

automatisch

Dateien mittels dem von PostfixAdmin mitgelieferten Skript POSTFIX CONF.txt erstellen

cd /var/www/postfixadmin/DOCUMENTS/
sh POSTFIX_CONF.txt

und danach vom temporärenVerzeichnis nach /etc/postfix/sql kopieren

sudo mv /tmp/postfixadmin-XXXXXX/* /etc/postfix/sql

manuell

virtual_alias_maps

Datei /etc/postfix/sql/mysql_virtual_alias_maps.cf mit folgenden Inhalt befüllen:

sudo vi /etc/postfix/sql/mysql_virtual_alias_maps.cf
user = postfix
password = <password>
hosts = <server ip>
dbname = postfix
query = SELECT goto FROM alias WHERE address='%s' AND active = '1'

Datei /etc/postfix/sql/mysql_virtual_alias_domain_maps.cf mit folgenden Inhalt befüllen:

sudo vi /etc/postfix/sql/mysql_virtual_alias_domain_maps.cf
user = postfix
password = <password>
hosts = <server ip>
dbname = postfix
query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('%u', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'

Datei /etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf mit folgenden Inhalt befüllen:

sudo vi /etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf
user = postfix
password = <password>
hosts = <server ip>
dbname = postfix
query  = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'
virtual_mailbox_maps

Datei /etc/postfix/sql/mysql_virtual_mailbox_maps.cf mit folgenden Inhalt befüllen:

sudo vi /etc/postfix/sql/mysql_virtual_mailbox_maps.cf
user = postfix
password = <password>
hosts = <server ip>
dbname = postfix
query = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1'

Datei /etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf mit folgenden Inhalt befüllen:

sudo vi /etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf
user = postfix
password = <password>
hosts = <server ip>
dbname = postfix
query = SELECT maildir FROM mailbox,alias_domain WHERE alias_domain.alias_domain = '%d' and mailbox.username = CONCAT('%u', '@', alias_domain.target_domain) AND mailbox.active = 1 AND alias_domain.active='1'
virtual_mailbox_domains

Datei /etc/postfix/sql/mysql_virtual_domains_maps.cf mit folgenden Inhalt befüllen:

sudo vi /etc/postfix/sql/mysql_virtual_domains_maps.cf
user = postfix
password = <password>
hosts = <server ip>
dbname = postfix
query = SELECT domain FROM domain WHERE domain='%s' AND active = '1'

Allgemein

Da die Dateien Passwörter enthalten, sollen sie nur für den Benutzer postfix lesbar sein:

sudo chown postfix:postfix /etc/postfix/sql/*.cf
sudo chmod 660 /etc/postfix/sql/*.cf

Postfix neustarten

sudo service postfix restart

Probleme

Quota-Support

Mar 17 14:23:35 LEROX2 postfix[14247]: /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: virtual_overquota_bounce=yes
Mar 17 14:23:35 LEROX2 postfix[14247]: /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: virtual_mailbox_limit_maps=mysql:/etc/postfix/sql/mysql_virtual_mailbox_limit_ma
Mar 17 14:23:35 LEROX2 postfix[14247]: /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: virtual_maildir_limit_message=Sorry, the user's maildir has overdrawn his disksp
Mar 17 14:23:35 LEROX2 postfix[14247]: /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: virtual_create_maildirsize=yes
Mar 17 14:23:35 LEROX2 postfix[14247]: /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: virtual_mailbox_extended=yes
Mar 17 14:23:35 LEROX2 postfix[14247]: /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: virtual_mailbox_limit_override=yes

Links

https://wiki.ubuntuusers.de/Postfix/

https://yomotherboard.com/setup-postfixadmin-virtual-email-users/


Zurück zu Mailserver einrichten