I'm testing sending out some emails via C#, but I can't tell what effect setting IsBodyHtml
to true
has. Regardless of the value, whatever I send in my Body shows up with a content type of "text/plain", and my HTML shows up tags and all in my email client (gmail). What is that flag actually supposed to do?
NOTE: I can send an HTML email just fine by creating an AlternateView
with a content type of "text/html", I just want to understand how setting the body is supposed to work.
I just wrestled with this same problem. My best solution was to avoid setting the
Body
property of theMailMessage
object at all. Instead just add twoAlternateView
s, first a plain text then an HTML. Make sure to add the plain text version first because the MIME standard says that:That means, that you put the plain text version first, so the clients should use the HTML version if possible.
IsBodyHtml – Specify whether body contains text or HTML mark up.
Body contain text or html markup that should be identify by IsBodyHtml.
Here is an excerpt for my SMTP helper I use everyday....
[UPDATE]
The key points as I originally left off...
IsBodyHtml states that your message is HTML formatted. If you were only sending a single view of HTML, this is all you need.
AlternateView is used to store my HTML, this is not required for sending a HTML message but it's required if you want to send a message that includes HTML and Plain Text, in case the receiver is unable to render the HTML.
I took out my plainView above so this isn't obvious, sorry...
The key here is that if you want to send a HTML formatted message you need to use IsBodyHtml = true (default is false) to have your content rendered as HTML.