Skip to content

Commit

Permalink
SmtpMessageChannel: Simplifying the processing of the "from" address
Browse files Browse the repository at this point in the history
  • Loading branch information
BenedekFarkas committed Mar 11, 2024
1 parent b5ad09e commit 44dcc86
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,16 @@ public void Process(IDictionary<string, object> parameters) {

mailMessage.Cc.AddRange(ParseRecipients(emailMessage.Cc));

var fromAddress = default(MailboxAddress);
if (!String.IsNullOrWhiteSpace(emailMessage.FromAddress)) {
fromAddress = MailboxAddress.Parse(emailMessage.FromAddress);
}
else {
// Take 'From' address from site settings or web.config.
fromAddress = !String.IsNullOrWhiteSpace(_smtpSettings.FromAddress)
? MailboxAddress.Parse(_smtpSettings.FromAddress)
: MailboxAddress.Parse(((SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp")).From);
}

mailMessage.Bcc.AddRange(ParseRecipients(emailMessage.Bcc));
fromAddress.Name = string.IsNullOrWhiteSpace(emailMessage.FromName) ? _smtpSettings.FromName : emailMessage.FromName;

var fromAddress = MailboxAddress.Parse(
// "From" address precendence: Current email message > site settings > configuration.
string.IsNullOrWhiteSpace(emailMessage.FromAddress)
? string.IsNullOrWhiteSpace(_smtpSettings.FromAddress)
? ((SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp")).From
: _smtpSettings.FromAddress
: emailMessage.FromAddress);
fromAddress.Name = string.IsNullOrWhiteSpace(emailMessage.FromName) ? _smtpSettings.FromName : emailMessage.FromName;
mailMessage.From.Add(fromAddress);

if (!String.IsNullOrWhiteSpace(emailMessage.ReplyTo)) {
Expand Down

0 comments on commit 44dcc86

Please sign in to comment.