开发者

C# MailMessage AlternateViews displaying HTML tags

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.CreateAlternateViewFromStrin开发者_如何学JAVAg("<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.


Does the message itself need to be marked around isBodyHtml ?

msg.IsBodyHtml = true;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜