From 156c95715165d8f567db181f0db3bef524cf85f9 Mon Sep 17 00:00:00 2001 From: "manuel.maier" Date: Tue, 20 May 2025 21:48:02 +0200 Subject: [PATCH] =?UTF-8?q?setup-email-pve.sh=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup-email-pve.sh | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 setup-email-pve.sh diff --git a/setup-email-pve.sh b/setup-email-pve.sh new file mode 100644 index 0000000..aab381a --- /dev/null +++ b/setup-email-pve.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +echo "=== [PVE] E-Mail-Benachrichtigungen (Web-GUI-kompatibel) ===" + +read -p "SMTP Server (z.B. smtp.example.com): " SMTP_SERVER +read -p "SMTP Port [587]: " SMTP_PORT +SMTP_PORT=${SMTP_PORT:-587} + +read -p "SMTP Benutzer (z.B. user@example.com): " SMTP_USER +read -s -p "SMTP Passwort: " SMTP_PASS +echo + +read -p "Absender-Adresse (z.B. pve@example.com): " MAIL_FROM +read -p "Empfänger-Adresse (z.B. admin@example.com): " MAIL_TO + +CONFIG_FILE="/etc/pve/datacenter.cfg" + +echo +echo "==> Konfiguration in $CONFIG_FILE wird gesetzt..." + +# Bestehende notify-Zeilen entfernen (falls vorhanden) +sed -i '/^notify:/d' "$CONFIG_FILE" + +# Neue Notify-Zeile setzen +echo "notify: $MAIL_TO" >> "$CONFIG_FILE" + +# Mail-Template konfigurieren (wenn noch nicht vorhanden) +MAIL_RC="/etc/postfix/sasl_passwd" +echo "[$SMTP_SERVER]:$SMTP_PORT $SMTP_USER:$SMTP_PASS" > "$MAIL_RC" + +# Postfix Konfiguration aktualisieren +postmap "$MAIL_RC" +chmod 600 "$MAIL_RC" +chown root:root "$MAIL_RC" + +# smtp_generic_maps (optional für FROM-Adresse) +echo "$SMTP_USER $MAIL_FROM" > /etc/postfix/generic +postmap /etc/postfix/generic + +postconf -e "smtp_use_tls = yes" +postconf -e "smtp_sasl_auth_enable = yes" +postconf -e "smtp_sasl_password_maps = hash:$MAIL_RC" +postconf -e "smtp_sasl_security_options = noanonymous" +postconf -e "smtp_generic_maps = hash:/etc/postfix/generic" +postconf -e "relayhost = [$SMTP_SERVER]:$SMTP_PORT" + +systemctl restart postfix + +echo +echo "==> Testmail wird gesendet..." +echo "Dies ist eine Testmail von Proxmox VE <$MAIL_FROM>" | mail -s "Testmail von Proxmox" -r "$MAIL_FROM" "$MAIL_TO" + +echo "==> Fertig! Konfiguration ist auch in der Web-GUI sichtbar."