views:

314

answers:

1

I have code that sends HTML emails to users. To accommodate users who dont have/ want HTML email, the email contains 2 alternate views, View(0) is HTML, View(1) is Plain text.

The HTML view has a header and footer graphics, but the style is done inline and not via css file. The text view is only the text; no tags, images, etc. The message has 3 pdf files attached.

When most users receive the message, it looks fine to them. No broken image links, no garbled text, etc.

When others get the message, one of 2 scenarios happen.

  • The entire HTML alternate view is packaged as an attachment (with the 3 pdfs as an attachment to it), and the parent message contains picture alphabet / random characters like this...

"㰡䑏䍔奐䔠桴浬⁐啂䱉䌠∭⼯圳䌯⽄呄⁈呍䰠㐮〱⁔牡湳楴楯湡氯⽅丢਍㰾਍桴浬਍㰾਍桥慤਍‾ഀ ਍㰀਍⽨敡搾਍਍㱢潤礠执捯汯爽∣晦晦晦∠瑥硴㴢⌰〰〰〢਍㰾਍扲਍㰾਍⽢潤社਍਍㰯桴浬਍ാ ਍� "

  • The Email is received with the attachments, but the text of the email is similar to the previous garble.

The email is sent using the System.Net.Mail classes. It reads an XML template to construct email messages, so its a bit long to post here but is pretty straight forward.

The users that have problems with the emails have come from comcast.net and other corporate addresses.

I do realize that from the receivers perspective that this is email is from an unknown sender, has graphics, has attachments, and therefore will likely be recognized as spam in some cases, but its what the biz wants, so they get it.

My gut tells me that this is some kind of encoding problem, I am using Unicode for all formats, is this a bad assumption? EDIT: checking this to sure up my understanding.

Does anybody have any idea what might be causing this, or a suggestion on what to do to remedy it?

EDIT @some: The html email has

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

at the top, but the AlternateView.CreateAlternateViewFromString() method is getting System.Text.Encoding.Unicode (utf-16) applied. I can see where this can be conflicting and will update it, but this will likely take some time to see if its fixed.

The users only get the email once when they complete a sign up process, but we have sent this same email to another comcast email account and had no problems viewing it.

Is encoding specific or forced by the OS or the email client (browser, outlook / express)?

(Please post as an answer so you can get votes if its helpful!)

+1  A: 

Ideally, as recommended by W3C, you should be encoding using UTF8.

This may do the trick.

adam
See the edit in the post, I am applying one encoding to the message body and another to the HTML in the body itself.
StingyJack
I'll take that as the answer.
StingyJack