tags:

views:

72

answers:

2

Hi All. I'm trying to send an html email to a gmail account, but for some reason, Google is stripping away the html from my email. The Html is preserved when I send to other accounts (non-gmail accounts) so I know that my html is correct.

Here's how I'm going about it:

  1. I have an aspx page, that I use as an email template.
  2. I grab the html from the aspx page from within a web service (done in C#)
  3. Dynamically fill in the non-static content through c# code within the web service.
  4. Send that as the email body.

Does anyone happen to know why gmail is removing the html? Thanks in advance.

+2  A: 

You need to be sure to set the IsBodyHtml property to true on your MailMessage:

var message = new MailMessage();
message.IsBodyHtml = true;
// Fill and send message here

Check out the MSDN reference for more info:

System.Net.Mail.MailMessage Members

Justin Niessner
A: 

The Html is preserved when I send to other accounts (non-gmail accounts) so I know that my html is correct.

It's not a programming issue. If it were, as you've observed, this would happen to all clients.

The issue is this: Most modern email clients allow users to choose to disallow html messages, or always view them as plain text. That could be what is happening here. You have to code to expect this, because you can't control user's preferences. If they have this enabled, and you send it as html only, it will look ugly to them.

However, for a solution to your issue, you should always be sending your mail as a Multi-Part Mime message to allow all clients to get a nice readable version.

David Stratton
Thanks David. I'll be sure to make sure it's Multi-Part Mime
JohnnyQuest