Gmail Showing Plain Text Version
January 30th, 2009I was just tweaking some code that sends out email. I noticed in Gmail that the plain text version of the email was being shown even though it was a multipart message with both plain text and HTML alternatives provided.
MailMessage msg = new MailMessage();
…
…
System.Net.Mail.AlternateView htmlView;
System.Net.Mail.AlternateView plainView;
System.Net.Mail.AlternateView plainView;
htmlView = AlternateView.CreateAlternateViewFromString(
htmlBody,
new ContentType("text/html"));
plainView = AlternateView.CreateAlternateViewFromString(
plainBody,
new ContentType("text/plain"));
msg.AlternateViews.Add(htmlView);
msg.AlternateViews.Add(plainView);
The fix was simple: add the plain text view to the message first. Yup, that’s all it took:
msg.AlternateViews.Add(plainView);
msg.AlternateViews.Add(htmlView);
msg.AlternateViews.Add(htmlView);


August 31st, 2009 at 1:26 pm
Thanks very much! This worked for me too. Also, I noticed that the text view version gets displayed as the preview content for the email in question when you are in your Inbox looking at the list of all emails…. which kinda makes sense.