Postfix (Ubuntu 16.04): Unterschied zwischen den Versionen
Zeile 121: | Zeile 121: | ||
##### Only allow mail transport if client is authenticated or in own network (PHP Scripts, ...) ###### | ##### 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 | smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination | ||
</pre> | |||
== Datenbankanbindung == | |||
=== Datenbank erstellen === | |||
<pre style="white-space: pre-wrap; | |||
white-space: -moz-pre-wrap; | |||
white-space: -pre-wrap; | |||
white-space: -o-pre-wrap; | |||
word-wrap: break-word;"> | |||
mysql -u root -p | |||
mysql> use mails; | |||
mysql> create table domains (id INT UNSIGNED AUTO_INCREMENT NOT NULL, domain VARCHAR(128) NOT NULL, UNIQUE (id), PRIMARY KEY (domain)); | |||
mysql> create table aliases (id INT UNSIGNED AUTO_INCREMENT NOT NULL, source VARCHAR(128) NOT NULL, destination VARCHAR(128) NOT NULL, UNIQUE (id), PRIMARY KEY (source, destination) ); | |||
mysql> quit; | |||
</pre> | |||
=== Datenbank befüllen === | |||
<pre style="white-space: pre-wrap; | |||
white-space: -moz-pre-wrap; | |||
white-space: -pre-wrap; | |||
white-space: -o-pre-wrap; | |||
word-wrap: break-word;"> | |||
mysql -u root -p | |||
mysql> use mails; | |||
mysql> insert into domains (domain) values ('domain.tld'); | |||
mysql> quit; | |||
</pre> | |||
Mittels Alias-Mail-Adressen kann man Mail an andere Adressen weiterleiten. Mittels nachfolgenden Datenbankeintrag kann werden Mails an ''test@domain.tld'' im Postfach von ''admin@domain.tld'' eingeordnet. | |||
<pre style="white-space: pre-wrap; | |||
white-space: -moz-pre-wrap; | |||
white-space: -pre-wrap; | |||
white-space: -o-pre-wrap; | |||
word-wrap: break-word;"> | |||
insert into aliases (source, destination) values ('test@domain.tld', 'admin@domain.tld'); | |||
</pre> | |||
=== Konfiguration === | |||
In der Datei ''/etc/postfix/main.cf'' die Datenbank-Konfigurations-Dateien eintragen: | |||
<pre style="white-space: pre-wrap; | |||
white-space: -moz-pre-wrap; | |||
white-space: -pre-wrap; | |||
white-space: -o-pre-wrap; | |||
word-wrap: break-word;"> | |||
###### MySQL Connection ###### | |||
virtual_alias_maps = mysql:/etc/postfix/virtual/mysql-aliases.cf | |||
virtual_mailbox_maps = mysql:/etc/postfix/virtual/mysql-maps.cf | |||
virtual_mailbox_domains = mysql:/etc/postfix/virtual/mysql-domains.cf | |||
local_recipient_maps = $virtual_mailbox_maps | |||
</pre> | |||
Eingetragene Dateipfade erstellen: | |||
<pre style="white-space: pre-wrap; | |||
white-space: -moz-pre-wrap; | |||
white-space: -pre-wrap; | |||
white-space: -o-pre-wrap; | |||
word-wrap: break-word;"> | |||
sudo mkdir /etc/postfix/virtual | |||
sudo chmod 660 /etc/postfix/virtual | |||
sudo touch /etc/postfix/virtual/mysql-aliases.cf | |||
sudo touch /etc/postfix/virtual/mysql-maps.cf | |||
sudo touch /etc/postfix/virtual/mysql-domains.cf | |||
</pre> | |||
==== Mit [[PostfixAdmin]] ==== | |||
Datei /etc/postfix/virtual/mysql-aliases.cf mit folgenden Inhalt befüllen: | |||
<pre> | |||
sudo nano /etc/postfix/virtual/mysql-aliases.cf | |||
</pre> | |||
<pre> | |||
user = postfix | |||
password = <password> | |||
hosts = <server ip> | |||
dbname = postfix | |||
query = SELECT goto FROM alias WHERE address='%s' | |||
</pre> | |||
Datei ''/etc/postfix/virtual/mysql-maps.cf'' mit folgenden Inhalt befüllen: | |||
<pre> | |||
sudo nano /etc/postfix/virtual/mysql-maps.cf | |||
</pre> | |||
<pre> | |||
user = postfix | |||
password = <password> | |||
hosts = <server ip> | |||
dbname = postfix | |||
query = SELECT * FROM mailbox WHERE local_part='%u' AND domain='%d' | |||
</pre> | |||
Datei ''/etc/postfix/virtual/mysql-domains.cf'' mit folgenden Inhalt befüllen: | |||
<pre> | |||
sudo nano /etc/postfix/virtual/mysql-domains.cf | |||
</pre> | |||
<pre> | |||
user = postfix | |||
password = <password> | |||
hosts = <server ip> | |||
dbname = postfix | |||
query = SELECT domain FROM domain WHERE domain='%s' | |||
</pre> | |||
{{note|Alias Domains funktionieren nicht}} | |||
[https://forum.ubuntuusers.de/topic/postfix-frage-zur-konfiguration/ https://forum.ubuntuusers.de/topic/postfix-frage-zur-konfiguration/] | |||
[http://www.postfix.org/postconf.5.html#virtual_alias_domains http://www.postfix.org/postconf.5.html#virtual_alias_domains] | |||
==== Ohne [[PostfixAdmin]] ==== | |||
Datei ''/etc/postfix/virtual/mysql-aliasis.cf'' mit folgenden Inhalt befüllen: | |||
<pre style="white-space: pre-wrap; | |||
white-space: -moz-pre-wrap; | |||
white-space: -pre-wrap; | |||
white-space: -o-pre-wrap; | |||
word-wrap: break-word;"> | |||
user = mailserver | |||
password = <password> | |||
hosts = <server ip> | |||
dbname = mails | |||
query = SELECT destination FROM aliases WHERE source='%s' | |||
</pre> | |||
Datei ''/etc/postfix/virtual/mysql-maps.cf'' mit folgenden Inhalt befüllen: | |||
<pre style="white-space: pre-wrap; | |||
white-space: -moz-pre-wrap; | |||
white-space: -pre-wrap; | |||
white-space: -o-pre-wrap; | |||
word-wrap: break-word;"> | |||
user = mailserver | |||
password = <password> | |||
hosts = <server ip> | |||
dbname = mails | |||
query = SELECT * FROM users WHERE username='%u' AND domain='%d' | |||
</pre> | |||
Datei ''/etc/postfix/virtual/mysql-domains.cf'' mit folgenden Inhalt befüllen: | |||
<pre style="white-space: pre-wrap; | |||
white-space: -moz-pre-wrap; | |||
white-space: -pre-wrap; | |||
white-space: -o-pre-wrap; | |||
word-wrap: break-word;"> | |||
user = mailserver | |||
password = <password> | |||
hosts = <server ip> | |||
dbname = mails | |||
query = SELECT * FROM domains WHERE domain='%s' | |||
</pre> | </pre> | ||
Version vom 3. März 2018, 15:34 Uhr
Noch in Bearbeitung
Installation
sudo apt-get install postfix postfix-mysql
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
Datenbank erstellen
mysql -u root -p mysql> use mails; mysql> create table domains (id INT UNSIGNED AUTO_INCREMENT NOT NULL, domain VARCHAR(128) NOT NULL, UNIQUE (id), PRIMARY KEY (domain)); mysql> create table aliases (id INT UNSIGNED AUTO_INCREMENT NOT NULL, source VARCHAR(128) NOT NULL, destination VARCHAR(128) NOT NULL, UNIQUE (id), PRIMARY KEY (source, destination) ); mysql> quit;
Datenbank befüllen
mysql -u root -p mysql> use mails; mysql> insert into domains (domain) values ('domain.tld'); mysql> quit;
Mittels Alias-Mail-Adressen kann man Mail an andere Adressen weiterleiten. Mittels nachfolgenden Datenbankeintrag kann werden Mails an test@domain.tld im Postfach von admin@domain.tld eingeordnet.
insert into aliases (source, destination) values ('test@domain.tld', 'admin@domain.tld');
Konfiguration
In der Datei /etc/postfix/main.cf die Datenbank-Konfigurations-Dateien eintragen:
###### MySQL Connection ###### virtual_alias_maps = mysql:/etc/postfix/virtual/mysql-aliases.cf virtual_mailbox_maps = mysql:/etc/postfix/virtual/mysql-maps.cf virtual_mailbox_domains = mysql:/etc/postfix/virtual/mysql-domains.cf local_recipient_maps = $virtual_mailbox_maps
Eingetragene Dateipfade erstellen:
sudo mkdir /etc/postfix/virtual sudo chmod 660 /etc/postfix/virtual sudo touch /etc/postfix/virtual/mysql-aliases.cf sudo touch /etc/postfix/virtual/mysql-maps.cf sudo touch /etc/postfix/virtual/mysql-domains.cf
Mit PostfixAdmin
Datei /etc/postfix/virtual/mysql-aliases.cf mit folgenden Inhalt befüllen:
sudo nano /etc/postfix/virtual/mysql-aliases.cf
user = postfix password = <password> hosts = <server ip> dbname = postfix query = SELECT goto FROM alias WHERE address='%s'
Datei /etc/postfix/virtual/mysql-maps.cf mit folgenden Inhalt befüllen:
sudo nano /etc/postfix/virtual/mysql-maps.cf
user = postfix password = <password> hosts = <server ip> dbname = postfix query = SELECT * FROM mailbox WHERE local_part='%u' AND domain='%d'
Datei /etc/postfix/virtual/mysql-domains.cf mit folgenden Inhalt befüllen:
sudo nano /etc/postfix/virtual/mysql-domains.cf
user = postfix password = <password> hosts = <server ip> dbname = postfix query = SELECT domain FROM domain WHERE domain='%s'
Alias Domains funktionieren nicht
https://forum.ubuntuusers.de/topic/postfix-frage-zur-konfiguration/
http://www.postfix.org/postconf.5.html#virtual_alias_domains
Ohne PostfixAdmin
Datei /etc/postfix/virtual/mysql-aliasis.cf mit folgenden Inhalt befüllen:
user = mailserver password = <password> hosts = <server ip> dbname = mails query = SELECT destination FROM aliases WHERE source='%s'
Datei /etc/postfix/virtual/mysql-maps.cf mit folgenden Inhalt befüllen:
user = mailserver password = <password> hosts = <server ip> dbname = mails query = SELECT * FROM users WHERE username='%u' AND domain='%d'
Datei /etc/postfix/virtual/mysql-domains.cf mit folgenden Inhalt befüllen:
user = mailserver password = <password> hosts = <server ip> dbname = mails query = SELECT * FROM domains WHERE domain='%s'
Links
https://wiki.ubuntuusers.de/Postfix/
https://yomotherboard.com/setup-postfixadmin-virtual-email-users/
Zurück zu Mailserver einrichten