【问题标题】:C# MailMessage AlternateViews displaying HTML tagsC# MailMessage AlternateViews 显示 HTML 标签
【发布时间】:2011-09-11 02:38:02
【问题描述】:

我在 C# 中使用 MailMessage 发送 HTML 电子邮件。我使用的代码如下

MailMessage msg = new MailMessage();
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("<B>Test Message</B>", null, "text/html");
msg.AlternateViews.Add(htmlView);

我使用备用视图是因为我需要在电子邮件正文中附加文件和嵌入图像。当我将电子邮件发送到我的 gmail 帐户时,我看到收件箱中显示了 HTML 标记。单击消息以查看实际的电子邮件可以消除标签。如何确保标签不显示在收件箱中?

谢谢

我解决了这个问题。我将解决方案发布为我自己问题的答案,以帮助可能遇到相同问题的其他人

我的代码有

MailMessage msg = new MailMessage();
msg.Body = "<B>Test Message</B>";
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("<B>Test Message</B>", null, "text/html");
msg.AlternateViews.Add(htmlView);

需要删除第二行代码,因为我同时指定了正文和备用视图,这导致了问题。

【问题讨论】:

    标签: c# html mailmessage


    【解决方案1】:

    消息本身是否需要在isBodyHtml 周围标记?

    msg.IsBodyHtml = true;
    

    【讨论】:

    • 我设置了 msg.IsBodyHtml = true 但这没有帮助
    猜你喜欢
    • 2019-08-12
    • 2019-02-01
    • 1970-01-01
    • 2016-07-22
    • 1970-01-01
    • 2015-10-24
    • 1970-01-01
    • 2023-01-24
    • 2023-03-13
    相关资源
    最近更新 更多