当客户端支持它时显示电子邮件为html,否则显示为纯文本/文本

时间:2013-11-06 13:57:39

标签: c# .net

如果客户端不支持html,我希望将电子邮件显示为html,以shud显示邮件为text / plain。我已经编写了代码,但不确定是否有人可以检查如何在这里检查多内容和多个mimetype。

mailMessage.IsBodyHtml = true;
mailMessage.From = new MailAddress(from);

foreach (string adress in to)
{
    mailMessage.To.Add(adress);
}

string path = string.Empty;

var htmlView = AlternateView.CreateAlternateViewFromString(mailMessage.Body, null, "text/html");

1 个答案:

答案 0 :(得分:0)

    ContentType mimeType = new System.Net.Mime.ContentType("text/html");

    // Add the alternate body to the message.               
    AlternateView alternate = AlternateView.CreateAlternateViewFromString(mailMessage.Body, mimeType);
    mailMessage.AlternateViews.Add(alternate);