In my last blog I asked how I could send unicode emails to hotmail, well Dave Wanta and www.AspNetEmail.com (no affiliate code, heh) to the rescue!
The AspNetEmail message takes a CharSet property, so far so good
As well as setting the CharSet to the relevant country setting, I found I also needed to HTML encode my message. I worked up a simple function knowing there was probably a better way ..
'HtmlBody = Server.HtmlEncode(HtmlBody) 'HtmlBody = Replace(HtmlBody, "<", "<", 1, -1, CompareMethod.Text) 'HtmlBody = Replace(HtmlBody, ">", ">", 1, -1, CompareMethod.Text) 'HtmlBody = Replace(HtmlBody, """, """", 1, -1, CompareMethod.Text) 'HtmlBody = Replace(HtmlBody, "'", "'", 1, -1, CompareMethod.Text) 'HtmlBody = Replace(HtmlBody, "&", "&", 1, -1, CompareMethod.Text)
.. and there was, already in AspNetEmail component - schweet!
Dim Util As New aspNetEmail.HtmlUtility Util.LoadString(HtmlBody, "http://www.URL.com/")
Util.HtmlEncodeOption = HtmlEncodeOption.NumberedCodes
Util.Render()
HtmlBody = Util.RenderedHtmlContent
msg.HtmlBodyPart = HtmlBody
It looks suspiciously like Hotmail explicitly rejects viewing UTF-8 encoded email - is this correct?
Unfortunately my content is in UTF-8 and I can't just ignore Hotmail users :O(
I am using AspNetEmail and I tried using ISO-8859-1 as the characterset. Didn't work. So I tried converting my UTF-8 encoded text into ISO-8859-1 using the following function
Function UTFISO(ByVal src As String) As String Dim iso As Encoding = Encoding.GetEncoding("iso-8859-1") Dim utf As Encoding = Encoding.UTF8 Dim unicodeBytes As Byte() = utf.GetBytes(src) Return iso.GetString(unicodeBytes) End Function Still no joy.
Any ideas anyone?