use MailboxAddress approach sugested by @jstedfast

This commit is contained in:
sbwalker
2025-09-21 08:09:11 -04:00
parent 3c528f0b93
commit 52745b1946

View File

@ -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}>";
}