#!/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."