System.Net.Mail AlternateViews丢失纯文本数据

时间:2009-02-18 14:25:18

标签: c# .net email

我正在尝试发送一封包含纯文本正文和备用html正文的电子邮件。 但是,当我窥探通过网络传输的数据时,电子邮件的文本部分就会丢失。

以下是我的编码尝试示例。

private static MailMessage BuildEmail(string plainText, string htmlBody)
{
    // Add the alternate body to the message.
    ContentType HtmlContentType = new ContentType("text/html");
    AlternateView alternate = AlternateView.CreateAlternateViewFromString(htmlBody, HtmlContentType);

    ContentType PlainContentType = new ContentType("text/plain");
    AlternateView PlainView = AlternateView.CreateAlternateViewFromString(plainText, PlainContentType);

    MailMessage mail = new MailMessage(new MailAddress(ToEmail_DEFAULT),
        new MailAddress(FromEmail_DEFAULT));

    mail.Subject = "First plain. Html next";
    mail.AlternateViews.Add(PlainView);
    mail.AlternateViews.Add(alternate);

    return mail;
}

http://www.my914.net/images/work/emailProblem.jpg

1 个答案:

答案 0 :(得分:1)

最终成为网络窥探应用程序的问题。 获取最新版本的应用程序后,我可以看到发送到SMTP服务器的数据是正确的,并且包含我的纯文本视图和html文本视图。