This Damn Thing Should Work

Monday, June 20, 2005

ASP.NET and HTML/Plaintext Emails

Here's the issue - we built a mass emailer (I know I know - contributing to the problem, blah blah) that we hooked up to a WYSIWYG HTML editor. Client generates her newsletters every month and sends em out.

I'm using ASP.NET, so I use the System.Web.Mail namespace and the MailMessage object to send out the emails, formatted in HTML. Everything works fine in testing, and we're all happy.

Then a few reports trickle in (along with example emails) of the text of the newsletter with all the text glommed together. I gathered from the people reporting this that they were using plaintext email readers. Basically the tags were being stripped and the email was sent out with what was left (which was a big glob of text).

My first reaction was surprise - I remember the days of plaintext email readers and getting an HTML formatted message usually consisted of the "this message is of Content-Type HTML" etc. that displayed a not so great looking version of the email - but you knew it was HTML and that was the issue. These messages were different - they looked like normal email plaintext messages - but they were coming from an HTML formatted message.

After a sizable amount of digging, I found out that the System.Web.Mail namespace automatically creates a plaintext version of HTML formatted messages and delivers the email as "multipart/alternative" which allows the plaintext readers to ignore the HTML version. This was a footnote on a website somewhere - couldn't find any reference to it on Microsoft's site...

After some more testing, I found out that our WYSIWYG was generating its break tags as <br/> rather than <br /> . I did a batch replace before sending the email and suddenly everything worked fine.

Sigh...

0 Comments:

Post a Comment

<< Home