本文介绍了我如何在AlternateView集编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过
创建mailBody 使用(VAR的StreamWriter =新的StreamWriter(fooFileName,假的,Encoding.UTF8))
{
streamWriter.Write(fooMessage);
}
现在我消耗此文件
VAR mailMessage =新System.Net.Mail.MailMessage
{
从= fooSender,
为了=
{
fooRecipient
},
主题= fooSubject,
SubjectEncoding = Encoding.UTF8,
BodyEncoding = Encoding.UTF8
};
// fooMediaType可
// - System.Net.Mime.MediaTypeNames.Text.Html
// - System.Net.Mime.MediaTypeNames.Text.Plain
VAR alternateView =新System.Net.Mail.AlternateView(fooFileName,fooMediaType);
mailMessage.AlternateViews.Add(alternateView);
如果我使用非变音,一切工作正常,但只要我使用变音符号在我的 alternateView
,他们都坏不了。
所以,我怎么可以设置某种编码的alternateView一切工作?
解决方案
VAR alternateView =新AlternateView(fooFileName,fooMediaType)
{
的ContentType =
{
字符集= Encoding.UTF8.WebName
}
};
I'm creating a mailBody via
using (var streamWriter = new StreamWriter(fooFileName, false, Encoding.UTF8))
{
streamWriter.Write(fooMessage);
}
now i'm consuming this file with
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);
If I'm using non-umlauts, everything works fine, but as soon as I'm using umlauts in my alternateView
, they get broken.
So how can I set some sort of encoding on the alternateView that everything is working?
解决方案
var alternateView = new AlternateView(fooFileName, fooMediaType)
{
ContentType =
{
CharSet = Encoding.UTF8.WebName
}
};
这篇关于我如何在AlternateView集编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!