Merge pull request #5640 from sbwalker/dev
improve NotificationJob validation logic
This commit is contained in:
@ -171,7 +171,7 @@ namespace Oqtane.Infrastructure
|
||||
// create mailbox addresses
|
||||
MailboxAddress to = null;
|
||||
MailboxAddress from = null;
|
||||
var error = "";
|
||||
var mailboxAddressValidationError = "";
|
||||
|
||||
// sender
|
||||
if (settingRepository.GetSettingValue(settings, "SMTPRelay", "False") != "True")
|
||||
@ -180,26 +180,42 @@ namespace Oqtane.Infrastructure
|
||||
fromName = string.IsNullOrEmpty(fromName) ? site.Name : fromName;
|
||||
}
|
||||
try
|
||||
{
|
||||
// exception handler is necessary because of https://github.com/jstedfast/MimeKit/issues/1186
|
||||
if (MailboxAddress.TryParse(fromEmail, out _))
|
||||
{
|
||||
from = new MailboxAddress(fromName, fromEmail);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// parse error creating sender mailbox address
|
||||
error += $" Invalid Sender: {fromName} <{fromEmail}>";
|
||||
}
|
||||
if (from == null)
|
||||
{
|
||||
|
||||
mailboxAddressValidationError += $" Invalid Sender: {fromName} <{fromEmail}>";
|
||||
}
|
||||
|
||||
// recipient
|
||||
try
|
||||
{
|
||||
// exception handler is necessary because of https://github.com/jstedfast/MimeKit/issues/1186
|
||||
if (MailboxAddress.TryParse(toEmail, out _))
|
||||
{
|
||||
to = new MailboxAddress(toName, toEmail);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// parse error creating recipient mailbox address
|
||||
error += $" Invalid Recipient: {toName} <{toEmail}>";
|
||||
}
|
||||
if (to == null)
|
||||
{
|
||||
mailboxAddressValidationError += $" Invalid Recipient: {toName} <{toEmail}>";
|
||||
}
|
||||
|
||||
// if mailbox addresses are valid
|
||||
if (from != null && to != null)
|
||||
{
|
||||
// create mail message
|
||||
@ -235,17 +251,18 @@ namespace Oqtane.Infrastructure
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// error
|
||||
log += $"Error Sending Notification Id: {notification.NotificationId} - {ex.Message}<br />";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log += $"Notification Id: {notification.NotificationId} Has An {error} And Has Been Deleted<br />";
|
||||
// invalid mailbox address
|
||||
log += $"Notification Id: {notification.NotificationId} Has An {mailboxAddressValidationError} And Has Been Deleted<br />";
|
||||
notification.IsDeleted = true;
|
||||
notificationRepository.UpdateNotification(notification);
|
||||
}
|
||||
}
|
||||
|
||||
log += "Notifications Delivered: " + sent + "<br />";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user