From c6e6c988759797a0daf42271cbfee50e3b394f66 Mon Sep 17 00:00:00 2001 From: Shaun Walker Date: Thu, 12 Jan 2023 09:13:13 -0500 Subject: [PATCH] improve notification job --- .../Infrastructure/Jobs/NotificationJob.cs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs b/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs index 7a184133..259fae53 100644 --- a/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs +++ b/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs @@ -96,7 +96,6 @@ namespace Oqtane.Infrastructure else { MailMessage mailMessage = new MailMessage(); - bool includeheader = true; // sender if (settings.ContainsKey("SMTPRelay") && settings["SMTPRelay"] == "True" && !string.IsNullOrEmpty(notification.FromEmail)) @@ -109,7 +108,6 @@ namespace Oqtane.Infrastructure { mailMessage.From = new MailAddress(notification.FromEmail); } - includeheader = false; } else { @@ -130,27 +128,29 @@ namespace Oqtane.Infrastructure mailMessage.Subject = notification.Subject; //body - if (includeheader) + mailMessage.Body = ""; + + // check if email is being sent from SMTP Sender rather than notification sender + if (!string.IsNullOrEmpty(notification.FromEmail) && mailMessage.From.Address != notification.FromEmail) { - if (!string.IsNullOrEmpty(notification.FromEmail) && !string.IsNullOrEmpty(notification.FromDisplayName)) + // include information of who sent the notification in the body + mailMessage.Body += "From: "; + if (!string.IsNullOrEmpty(notification.FromDisplayName)) { - mailMessage.Body = "From: " + notification.FromDisplayName + "<" + notification.FromEmail + ">" + "\n"; + mailMessage.Body += notification.FromDisplayName + " <" + notification.FromEmail + ">\n"; } else { - mailMessage.Body = "From: " + site.Name + "\n"; - } - mailMessage.Body += "Sent: " + notification.CreatedOn + "\n"; - if (!string.IsNullOrEmpty(notification.ToDisplayName)) - { - mailMessage.Body += "To: " + notification.ToDisplayName + "<" + notification.ToEmail + ">" + "\n"; - } - else - { - mailMessage.Body += "To: " + notification.ToEmail + "\n"; + mailMessage.Body += notification.FromEmail + "\n"; } + } - mailMessage.Body += notification.Body; + // check if notification was created in the past + if (notification.CreatedOn.Date != DateTime.UtcNow.Date) + { + mailMessage.Body += "Sent: " + notification.CreatedOn + "\n"; + } + mailMessage.Body += "\n" + notification.Body; // encoding mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;