Skip to content

Commit

Permalink
DNN-30859 - Set AlternativeView.Encoding with bodyEncoding
Browse files Browse the repository at this point in the history
- This is to ensure AlternativeView encoding is always consistent
with bodyEncoding and not relying on the body text
- Extract the code to AddAlternateView method to allow UTs
  • Loading branch information
tingung committed Jul 19, 2019
1 parent 2ad29fc commit 455b8cb
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions DNN Platform/Library/Services/Mail/Mail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,7 @@ private static string SendMailInternal(MailMessage mailMessage, string subject,
mailMessage.Subject = HtmlUtils.StripWhiteSpace(subject, true);
mailMessage.BodyEncoding = bodyEncoding;

//added support for multipart html messages
//add text part as alternate view
var PlainView = AlternateView.CreateAlternateViewFromString(ConvertToText(body), null, "text/plain");
mailMessage.AlternateViews.Add(PlainView);
if (mailMessage.IsBodyHtml)
{
var HTMLView = AlternateView.CreateAlternateViewFromString(body, null, "text/html");
mailMessage.AlternateViews.Add(HTMLView);
}
AddAlternateView(mailMessage, body, bodyEncoding);

smtpServer = smtpServer.Trim();
if (SmtpServerRegex.IsMatch(smtpServer))
Expand Down Expand Up @@ -198,6 +190,19 @@ private static string SendMailInternal(MailMessage mailMessage, string subject,
return retValue;
}

internal static void AddAlternateView(MailMessage mailMessage, string body, Encoding bodyEncoding)
{
//added support for multipart html messages
//add text part as alternate view
var PlainView = AlternateView.CreateAlternateViewFromString(ConvertToText(body), bodyEncoding, "text/plain");
mailMessage.AlternateViews.Add(PlainView);
if (mailMessage.IsBodyHtml)
{
var HTMLView = AlternateView.CreateAlternateViewFromString(body, bodyEncoding, "text/html");
mailMessage.AlternateViews.Add(HTMLView);
}
}

#endregion

#region Public Methods
Expand Down

0 comments on commit 455b8cb

Please sign in to comment.