Merge pull request #5729 from sbwalker/dev
fix #5705 - improve error handling and efficiency in NotificationJob - credit @beolafsen
This commit is contained in:
@@ -42,6 +42,9 @@ namespace Oqtane.Infrastructure
|
||||
{
|
||||
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
|
||||
var settings = settingRepository.GetSettings(EntityNames.Site, site.SiteId, EntityNames.Host, -1);
|
||||
|
||||
@@ -75,12 +78,13 @@ namespace Oqtane.Infrastructure
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (valid)
|
||||
{
|
||||
// construct SMTP Client
|
||||
using var client = new SmtpClient();
|
||||
|
||||
try
|
||||
{
|
||||
var secureSocketOptions = SecureSocketOptions.Auto;
|
||||
switch (settingRepository.GetSettingValue(settings, "SMTPSSL", "Auto"))
|
||||
{
|
||||
@@ -106,7 +110,15 @@ namespace Oqtane.Infrastructure
|
||||
await client.ConnectAsync(settingRepository.GetSettingValue(settings, "SMTPHost", ""),
|
||||
int.Parse(settingRepository.GetSettingValue(settings, "SMTPPort", "")),
|
||||
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")
|
||||
{
|
||||
// it is possible to use basic without any authentication (not recommended)
|
||||
@@ -135,12 +147,12 @@ namespace Oqtane.Infrastructure
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (valid)
|
||||
{
|
||||
// iterate through undelivered notifications
|
||||
int sent = 0;
|
||||
List<Notification> notifications = notificationRepository.GetNotifications(site.SiteId, -1, -1).ToList();
|
||||
foreach (Notification notification in notifications)
|
||||
{
|
||||
var fromEmail = notification.FromEmail ?? "";
|
||||
@@ -255,7 +267,12 @@ namespace Oqtane.Infrastructure
|
||||
}
|
||||
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 />";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user