我有一个 ASP.Net/MVC 应用程序,我正在尝试发送 HTML 电子邮件。我通过读取带有标记的 HTML 文件,然后替换标记来完成此操作。这部分很好,生成的 HTML 正是我想要的,但是当我发送电子邮件时,我收到的内容看起来像 -
<style type=3D"text/css">=
=0D=0A.styleTitles=0D=0A{=0D=0Afont-weight:=bold;=0D=0A}=0D=0A
.style1=0D=0A {=0D=0A
并且应该看起来像
<style type="text/css">
.styleTitles
{
font-weight: bold;
}
.style1
{
height: 15px;
}
我在网上查看过,似乎找不到发送消息的正确语法。我见过一些解决方案,但似乎没有一个有效。
我当前的测试代码是 -
SmtpClient smtpclient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress SendFrom = new MailAddress("[email protected] /cdn-cgi/l/email-protection");
MailAddress SendTo = new MailAddress("[email protected] /cdn-cgi/l/email-protection");
MailMessage MyMessage = new MailMessage(SendFrom, SendTo);
var plainView = AlternateView.CreateAlternateViewFromString(msgBody,null,"text/html");
plainView.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;
MyMessage.AlternateViews.Add(plainView);
MyMessage.IsBodyHtml = true;
MyMessage.Subject = subjectLine;
MyMessage.Body = msgBody;
smtpclient.Send(MyMessage);
有什么建议么?
也许是这样的:
var plainView = AlternateView.CreateAlternateViewFromString(msgBody, new ContentType("text/plain; charset=UTF-8"));
MyMessage.AlternateViews.Add(plainView);
MyMessage.BodyEncoding = Encoding.UTF8;
MyMessage.IsBodyHtml = true;
MyMessage.Subject = subjectLine;
MyMessage.Body = msgBody;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)