C# MailMessage AlternateViews 显示 HTML 标签
我正在 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);
需要删除第二行代码,因为我指定了导致问题的主体和备用视图。
I am using MailMessage in C# to send out a HTML email. The code I am using is as follows
MailMessage msg = new MailMessage();
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("<B>Test Message</B>", null, "text/html");
msg.AlternateViews.Add(htmlView);
I use the Alternate view because I need to attach files and embed images in the email body. When I send out the email to my gmail account, I see the HTML tags displayed in the inbox. Clicking on the message to view the actual email gets rid of the tags. How do I ensure that the tags do not display in the inbox?
Thanks
I solved the issue. I am posting the solution as an answer to my own question to help others who may run into the same issue
My code had
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);
The second line of code needed to be removed since I was specifying both a body and an alternate view which was causing problems.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
消息本身是否需要在
isBodyHtml
周围进行标记?Does the message itself need to be marked around
isBodyHtml
?