From 52745b194657ea960e683aef9e6f58e455d44f44 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Sun, 21 Sep 2025 08:09:11 -0400 Subject: [PATCH] use MailboxAddress approach sugested by @jstedfast --- .../Infrastructure/Jobs/NotificationJob.cs | 28 ++++--------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs b/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs index c85663e8..7771d8c1 100644 --- a/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs +++ b/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs @@ -179,38 +179,22 @@ namespace Oqtane.Infrastructure fromEmail = settingRepository.GetSettingValue(settings, "SMTPSender", ""); fromName = string.IsNullOrEmpty(fromName) ? site.Name : fromName; } - try + if (MailboxAddress.TryParse(fromEmail, out from)) { - // exception handler is necessary because of https://github.com/jstedfast/MimeKit/issues/1186 - if (MailboxAddress.TryParse(fromEmail, out _)) - { - from = new MailboxAddress(fromName, fromEmail); - } + from.Name = fromName; } - catch - { - // parse error creating sender mailbox address - } - if (from == null) + else { mailboxAddressValidationError += $" Invalid Sender: {fromName} <{fromEmail}>"; } // recipient - try + if (MailboxAddress.TryParse(toEmail, out to)) { - // exception handler is necessary because of https://github.com/jstedfast/MimeKit/issues/1186 - if (MailboxAddress.TryParse(toEmail, out _)) - { - to = new MailboxAddress(toName, toEmail); - } + to.Name = toName; } - catch - { - // parse error creating recipient mailbox address - } - if (to == null) + else { mailboxAddressValidationError += $" Invalid Recipient: {toName} <{toEmail}>"; }