我正在通过
创建一个mailBodyusing (var streamWriter = new StreamWriter(fooFileName, false, Encoding.UTF8))
{
streamWriter.Write(fooMessage);
}
现在我正在使用
来使用此文件var mailMessage = new System.Net.Mail.MailMessage
{
From = fooSender,
To =
{
fooRecipient
},
Subject = fooSubject,
SubjectEncoding = Encoding.UTF8,
BodyEncoding = Encoding.UTF8
};
// fooMediaType can be
// - System.Net.Mime.MediaTypeNames.Text.Html
// - System.Net.Mime.MediaTypeNames.Text.Plain
var alternateView = new System.Net.Mail.AlternateView(fooFileName, fooMediaType);
mailMessage.AlternateViews.Add(alternateView);
如果我使用非变音符号,一切正常,但只要我在alternateView
中使用变音符号,它们就会被破坏。
那么如何在alternateView上设置某种编码,以确保一切正常?
答案 0 :(得分:16)
var alternateView = new AlternateView(fooFileName, fooMediaType)
{
ContentType =
{
CharSet = Encoding.UTF8.WebName
}
};