我有一些代码可以发送电子邮件。电子邮件的数据来自第三方API,它看起来像å
,相当于丹麦字符å
。但电子邮件显示s å
。
有什么方法可以改变这个来纠正吗?
我发送邮件的代码就像这样
SmtpClient client = new SmtpClient();
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
foreach (string toEmail in toEmails.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
mail.To.Add(toEmail.Trim());
mail.Subject = subject;
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = body;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = isHtml;
mail.Priority = MailPriority.Normal;
if (attachments != null)
{
foreach (string key in attachments.Keys)
{
Attachment mailAttachment = new Attachment(attachments[key], key);
mail.Attachments.Add(mailAttachment);
}
}
client.Send(mail);
retValue = true;
注意:使用L.B的答案解决了这个问题。但我仍然有一些问题,如 这个。在我的电子邮件正文中
答案 0 :(得分:3)
var str = HttpUtility.HtmlDecode("å");
var str = WebUtility.HtmlDecode("å");