Proxmox: Mailversand via Relay
Postfix installieren (sofern noch nicht erfolgt)
|
1 2 |
apt-get install postfix systemctl enable postfix |
Postfix konfigurieren
Konfigurationsdatei /etc/postfix/main.cf
|
1 2 3 4 |
myhostname = pve.example.com mydestination = $myhostname, localhost.$mydomain, localhost mynetworks = 127.0.0.0/8 inet_interfaces = loopback-only |
Natürlich müssen die entsprechenden Werte für die Attribute myhostname (FQDN des lokalen Systems). Ziel ist es, dass nur vom lokalen System E-Mails entgegengenommen (und weitergeleitet) werden.
E-Mail Relay installieren
|
1 |
apt-get install libsasl2-modules |
Konfigurationsdatei /etc/postfix/main.cf
|
1 2 3 4 5 6 7 8 9 10 |
relayhost = [mailserver-to-forward-to]:[port] ... smtp_sasl_auth_enable = yes smtp_sasl_security_options = noanonymous smtp_sasl_tls_security_options = noanonymous smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_tls_security_level = encrypt smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt smtp_tls_wrappermode = yes header_size_limit = 4096000 |
Wobei der Relayhost dem Mailserver des E-Mail-Anbieters, über welchen versendet werden soll, entsprechen muss.
Zugangsdaten hinterlegen
Datei /etc/postfix/sasl_passwd
|
1 |
[relayhost]:[port] username:password |
Nach Änderungen muss das Postfixmapping aktualisiert werden. Dadurch wird eine neue Datei erzeugt: /etc/postfix/sasl_passwd.db
|
1 2 |
postmap /etc/postfix/sasl_passwd systemctl restart postfix.service |
Anschließend wird die Datei auf den User root beschränkt
|
1 2 |
chown "root:root" "/etc/postfix/sasl_passwd" chmod 0600 "/etc/postfix/sasl_passwd" |
Absenderadresse mit RegEx überschreiben
Konfigurationsdatei /etc/postfix/main.cf
|
1 2 3 |
sender_canonical_classes = envelope_sender, header_sender sender_canonical_maps = regexp:/etc/postfix/sender_canonical smtp_header_checks = regexp:/etc/postfix/header_check |
Datei mit der Regular Expression Definition für das Attribut „sender_canonical_maps“ /etc/postfix/sender_canonical
|
1 |
/.+/ do-not-reply@[Abenderdomain].[tld] |
Datei mit der Regular Expression Definition für das Attribut „smtp_header_checks“ /etc/postfix/header_check
|
1 |
/From:.*/ REPLACE From: [yourhostname] (Proxmox, PVE) <do-not-reply@example.com> |
Anschleßend wieder das Postfixmapping aktualisieren und die Dateien auf den User root beschränken
|
1 2 3 4 5 |
postmap /etc/postfix/sender_canonical chown "root:root" "/etc/postfix/sender_canonical" chmod 0600 "/etc/postfix/sender_canonical" chown "root:root" "/etc/postfix/header_check" chmod 0600 "/etc/postfix/header_check" |
Root Alias
Datei /etc/aliases
|
1 2 |
... root: [adresse]@[domain].[tld] |
Anschließend die Postfix Alias Datenbank aktualisieren
|
1 |
postalias /etc/aliases |
Mailadresse im Proxmox User hinterlegen
Für den jeweiligen Benutzer die entsprechende E-Mailadresse im User hinterlegen (Proxmox GUI).
Test
|
1 2 3 4 |
systemctl restart postfix.service systemctl status postfix.service echo "Hello World Message" | mail -s "Hello World Subject from $(hostname)" "your-mail-adress-to-receive" journalctl -f -u postfix* |