use MailboxAddress approach sugested by @jstedfast
This commit is contained in:
@ -179,38 +179,22 @@ namespace Oqtane.Infrastructure
|
|||||||
fromEmail = settingRepository.GetSettingValue(settings, "SMTPSender", "");
|
fromEmail = settingRepository.GetSettingValue(settings, "SMTPSender", "");
|
||||||
fromName = string.IsNullOrEmpty(fromName) ? site.Name : fromName;
|
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
|
from.Name = fromName;
|
||||||
if (MailboxAddress.TryParse(fromEmail, out _))
|
|
||||||
{
|
|
||||||
from = new MailboxAddress(fromName, fromEmail);
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
catch
|
|
||||||
{
|
|
||||||
// parse error creating sender mailbox address
|
|
||||||
}
|
|
||||||
if (from == null)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
mailboxAddressValidationError += $" Invalid Sender: {fromName} <{fromEmail}>";
|
mailboxAddressValidationError += $" Invalid Sender: {fromName} <{fromEmail}>";
|
||||||
}
|
}
|
||||||
|
|
||||||
// recipient
|
// recipient
|
||||||
try
|
if (MailboxAddress.TryParse(toEmail, out to))
|
||||||
{
|
{
|
||||||
// exception handler is necessary because of https://github.com/jstedfast/MimeKit/issues/1186
|
to.Name = toName;
|
||||||
if (MailboxAddress.TryParse(toEmail, out _))
|
|
||||||
{
|
|
||||||
to = new MailboxAddress(toName, toEmail);
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
catch
|
|
||||||
{
|
|
||||||
// parse error creating recipient mailbox address
|
|
||||||
}
|
|
||||||
if (to == null)
|
|
||||||
{
|
{
|
||||||
mailboxAddressValidationError += $" Invalid Recipient: {toName} <{toEmail}>";
|
mailboxAddressValidationError += $" Invalid Recipient: {toName} <{toEmail}>";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user