4

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.

1 Answer 1

3

Does the message itself need to be marked around isBodyHtml ?

msg.IsBodyHtml = true;
Sign up to request clarification or add additional context in comments.

1 Comment

I have msg.IsBodyHtml = true set but that doesnt help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.