Merge pull request #5729 from sbwalker/dev

fix #5705 - improve error handling and efficiency in NotificationJob - credit @beolafsen
This commit is contained in:
Shaun Walker
2025-10-19 14:03:23 -04:00
committed by GitHub

View File

@@ -42,6 +42,9 @@ namespace Oqtane.Infrastructure
{ {
log += "Processing Notifications For Site: " + site.Name + "<br />"; log += "Processing Notifications For Site: " + site.Name + "<br />";
List<Notification> notifications = notificationRepository.GetNotifications(site.SiteId, -1, -1).ToList();
if (notifications.Count > 0)
{
// get site settings // get site settings
var settings = settingRepository.GetSettings(EntityNames.Site, site.SiteId, EntityNames.Host, -1); var settings = settingRepository.GetSettings(EntityNames.Site, site.SiteId, EntityNames.Host, -1);
@@ -75,12 +78,13 @@ namespace Oqtane.Infrastructure
} }
} }
if (valid) if (valid)
{ {
// construct SMTP Client // construct SMTP Client
using var client = new SmtpClient(); using var client = new SmtpClient();
try
{
var secureSocketOptions = SecureSocketOptions.Auto; var secureSocketOptions = SecureSocketOptions.Auto;
switch (settingRepository.GetSettingValue(settings, "SMTPSSL", "Auto")) switch (settingRepository.GetSettingValue(settings, "SMTPSSL", "Auto"))
{ {
@@ -106,7 +110,15 @@ namespace Oqtane.Infrastructure
await client.ConnectAsync(settingRepository.GetSettingValue(settings, "SMTPHost", ""), await client.ConnectAsync(settingRepository.GetSettingValue(settings, "SMTPHost", ""),
int.Parse(settingRepository.GetSettingValue(settings, "SMTPPort", "")), int.Parse(settingRepository.GetSettingValue(settings, "SMTPPort", "")),
secureSocketOptions); secureSocketOptions);
}
catch (Exception ex)
{
log += "SMTP Not Configured Properly In Site Settings - Could Not Connect To SMTP Server - " + ex.Message + "<br />";
valid = false;
}
if (valid)
{
if (settingRepository.GetSettingValue(settings, "SMTPAuthentication", "Basic") == "Basic") if (settingRepository.GetSettingValue(settings, "SMTPAuthentication", "Basic") == "Basic")
{ {
// it is possible to use basic without any authentication (not recommended) // it is possible to use basic without any authentication (not recommended)
@@ -135,12 +147,12 @@ namespace Oqtane.Infrastructure
valid = false; valid = false;
} }
} }
}
if (valid) if (valid)
{ {
// iterate through undelivered notifications // iterate through undelivered notifications
int sent = 0; int sent = 0;
List<Notification> notifications = notificationRepository.GetNotifications(site.SiteId, -1, -1).ToList();
foreach (Notification notification in notifications) foreach (Notification notification in notifications)
{ {
var fromEmail = notification.FromEmail ?? ""; var fromEmail = notification.FromEmail ?? "";
@@ -255,7 +267,12 @@ namespace Oqtane.Infrastructure
} }
else else
{ {
log += "Site Deleted Or SMTP Disabled In Site Settings" + "<br />"; log += "Site Deleted Or SMTP Disabled In Site Settings<br />";
}
}
else
{
log += "No Notifications To Deliver<br />";
} }
} }