setup-email-pve.sh aktualisiert

This commit is contained in:
2025-05-20 22:20:43 +02:00
parent 4bc66c4141
commit e41a80499e

View File

@@ -1,53 +1,32 @@
#!/bin/bash #!/bin/bash
echo "=== [PVE] E-Mail-Benachrichtigungen (Web-GUI-kompatibel) ===" echo "=== Proxmox VE 8 Benachrichtigungssystem konfigurieren ==="
read -p "SMTP Server (z.B. smtp.example.com): " SMTP_SERVER read -p "SMTP Server: " SMTP_SERVER
read -p "SMTP Port [587]: " SMTP_PORT read -p "SMTP Port [587]: " SMTP_PORT
SMTP_PORT=${SMTP_PORT:-587} SMTP_PORT=${SMTP_PORT:-587}
read -p "SMTP Benutzer (z.B. user@example.com): " SMTP_USER read -p "SMTP Benutzer: " SMTP_USER
read -s -p "SMTP Passwort: " SMTP_PASS read -s -p "SMTP Passwort: " SMTP_PASS
echo echo
read -p "Absender-Adresse (z.B. pve@example.com): " MAIL_FROM read -p "Absender-Adresse: " MAIL_FROM
read -p "Empfänger-Adresse (z.B. admin@example.com): " MAIL_TO read -p "Mail-Zieladresse: " MAIL_TO
CONFIG_FILE="/etc/pve/datacenter.cfg" # Sender erstellen
pvesh create /config/notifications/senders/default --mailname "$(hostname -f)" \
--mailfrom "$MAIL_FROM" --smarthost "$SMTP_SERVER:$SMTP_PORT" \
--authuser "$SMTP_USER" --password "$SMTP_PASS" --type smtp
# Ziel konfigurieren
pvesh create /config/notifications/targets/mail-admin --type sendmail \
--mailto "$MAIL_TO"
# Policy setzen (optional)
pvesh set /config/notifications/policy/default --targets mail-admin --sender default
echo echo
echo "==> Konfiguration in $CONFIG_FILE wird gesetzt..." echo "==> Testmail wird versendet..."
proxmox-notify test --target mail-admin --subject "Test von $(hostname)" --body "Das ist eine Testmail vom neuen Benachrichtigungssystem (PVE 8)."
# Bestehende notify-Zeilen entfernen (falls vorhanden) echo "==> Konfiguration abgeschlossen. Überprüfbar in der Web-GUI unter Rechenzentrum → Benachrichtigungen."
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."