mirror of
https://github.com/swissmakers/fail2ban-ui.git
synced 2026-04-17 05:53:15 +02:00
Fix a bug where no mail and no db-entries are made if mailfunction returns 500
This commit is contained in:
@@ -886,13 +886,10 @@ func HandleBanNotification(ctx context.Context, server config.Fail2banServer, ip
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send email notification
|
// Send email notification (best-effort; the ban event is already recorded)
|
||||||
if err := sendBanAlert(ip, jail, hostname, failures, whoisData, filteredLogs, country, settings); err != nil {
|
if err := sendBanAlert(ip, jail, hostname, failures, whoisData, filteredLogs, country, settings); err != nil {
|
||||||
log.Printf("❌ Failed to send alert email: %v", err)
|
log.Printf("❌ Failed to send ban alert email: %v", err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("✅ Email alert sent for banned IP %s (%s)", ip, displayCountry)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -973,13 +970,10 @@ func HandleUnbanNotification(ctx context.Context, server config.Fail2banServer,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send email notification
|
// Send email notification (best-effort; the unban event is already recorded)
|
||||||
if err := sendUnbanAlert(ip, jail, hostname, whoisData, country, settings); err != nil {
|
if err := sendUnbanAlert(ip, jail, hostname, whoisData, country, settings); err != nil {
|
||||||
log.Printf("❌ Failed to send unban alert email: %v", err)
|
log.Printf("❌ Failed to send unban alert email: %v", err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("✅ Email alert sent for unbanned IP %s (%s)", ip, displayCountry)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2587,7 +2581,7 @@ func sendEmail(to, subject, body string, settings config.AppSettings) error {
|
|||||||
// Skip sending if the destination email is still the default placeholder
|
// Skip sending if the destination email is still the default placeholder
|
||||||
if strings.EqualFold(strings.TrimSpace(to), "alerts@example.com") {
|
if strings.EqualFold(strings.TrimSpace(to), "alerts@example.com") {
|
||||||
log.Printf("⚠️ sendEmail skipped: destination email is still the default placeholder (alerts@example.com). Please update the 'Destination Email' in Settings → Alert Settings.")
|
log.Printf("⚠️ sendEmail skipped: destination email is still the default placeholder (alerts@example.com). Please update the 'Destination Email' in Settings → Alert Settings.")
|
||||||
return errors.New("destination email is still the default (alerts@example.com) - please configure a valid address in Settings → Alert Settings")
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate SMTP settings
|
// Validate SMTP settings
|
||||||
|
|||||||
Reference in New Issue
Block a user