4

我在 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);

需要删除第二行代码,因为我同时指定了导致问​​题的主体和替代视图。

4

1 回答 1

3

消息本身是否需要标记isBodyHtml

msg.IsBodyHtml = true;
于 2011-06-08T18:04:48.670 回答