我正在通过此函数发送文本/HTML 邮件,此处 BodyMessage 和 mailSubject 是 Html 文本。
但是当收到邮件时,它包含像 &ldquo,&rdquo, ' 我怎样才能删除它们的符号。
public static bool SendMailByTemplates(string toAddress, string ccAddress, string bccAddress, string mailSubject, string bodyMessage, List<KeyValuePair<string, String>> attachmentFile)
{
MailMessage msg = new MailMessage();
GetConfigurationForAdmin();
GetConfiguration();
SmtpClient mailClient = new SmtpClient();
if (toAddress == "Admin")
{
toAddress = toAdmin;
}
else if (ccAddress == "Admin")
{
ccAddress = toAdmin;
}
msg.From = new MailAddress(fromAddress);
msg.To.Add(new MailAddress(toAddress));
if (ccAddress != "" && ccAddress != null)
msg.CC.Add(new MailAddress(ccAddress));
if (bccAddress != "" && bccAddress != null)
msg.Bcc.Add(new MailAddress(bccAddress));
LinkedResource headerlogo = new LinkedResource(HttpContext.Current.Server.MapPath("~/Content/Images/EmailTemplateImages/logo.jpg"));
headerlogo.ContentId = "headerlogo";
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(bodyMessage, null, MediaTypeNames.Text.Html);
htmlView.LinkedResources.Add(headerlogo);
htmlView.LinkedResources.Add(greenlogo);
htmlView.LinkedResources.Add(skylinelogo);
msg.Subject = mailSubject;
/* msg.Body = bodyMessage;
msg.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8");
*/
if (attachmentFile != null)
{
foreach (KeyValuePair<string, String> attachment in attachmentFile)
{
if (!(attachment.Key == null || attachment.Key == ""))
{
Attachment attach = new Attachment(attachment.Key);
attach.Name = attachment.Value;
msg.Attachments.Add(attach);
}
}
}
msg.IsBodyHtml = true;
NetworkCredential basicAuthenticationInfo = new NetworkCredential(fromAddress, password);
mailClient.Host = host;
mailClient.Port = port;
mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = basicAuthenticationInfo;
System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(System.Text.RegularExpressions.Regex.Replace(bodyMessage, @"<(.|\n)*?>", string.Empty), null, "text/plain");
msg.AlternateViews.Add(plainView);
msg.AlternateViews.Add(htmlView);
msg.ReplyTo = new MailAddress(replyAddress);
mailClient.Send(msg);
}
}
任何人都可以为我提供上述问题的解决方案。