HighTechTalks DotNet Forums  

still having a problem with HTML AlternateView in mail message

Dotnet Framework (SDK) microsoft.public.dotnet.framework.sdk


Discuss still having a problem with HTML AlternateView in mail message in the Dotnet Framework (SDK) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
David Thielen
 
Posts: n/a

Default still having a problem with HTML AlternateView in mail message - 10-07-2009 , 12:35 PM






Original problem:
To create an HTML version of a mail message I do:

StreamReader htmlStream = new StreamReader(html.GetReport(),
Encoding.UTF8);

MailMessage mail = new MailMessage();

mail.AlternateViews.Add(new AlternateView(htmlStream.BaseStream,
MediaTypeNames.Text.Html));

The mail when it arrives has the characters 0xEF, 0xBB, 0xBF (which
are the preamble chars). And the StreamReader has them as it's
preamble.

The problem is, they show up on the page of the email. So MailMessage
does not know to not display them.

So I tried getting rid of the StreamReader and did:

string htmlMailMsg =
Encoding.UTF8.GetString(((MemoryStream)html.GetRep ort()).GetBuffer());
MemoryStream ms = new
MemoryStream(Encoding.ASCII.GetBytes(htmlMailMsg)) ;
mail.AlternateViews.Add(new AlternateView(ms,
MediaTypeNames.Text.Html));

Now I get a ? at the top of the message. The memory stream has no
preamble as best as I can tell.

Any idea how to avoid this?

thanks - dave

david@at-at-at (AT) windward (DOT) dot.dot.net
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm

Reply With Quote
  #2  
Old   
Jialiang Ge [MSFT]
 
Posts: n/a

Default RE: still having a problem with HTML AlternateView in mail message - 10-08-2009 , 03:57 AM






Hello Dave

(MemoryStream)html.GetReport()).GetBuffer() returns a byte array of the
message. If you do not intend to display the preamble bytes (0xEF, 0xBB,
0xBF), could you remove those bytes from this byte array? For example:

byte[] data = new byte[] { 0xa, 0xb, 0xc, 0xEF, 0xBB, 0xBF,
0x1, 0x2, 0x3 };
List<byte> list = new List<byte>(data.Length);
foreach (byte b in data)
{
if (b != 0xEF && b!= 0xBB && b!= 0xBF)
list.Add(b);
}
byte[] result = list.ToArray();

Regards,
Jialiang Ge
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg (AT) microsoft (DOT) com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

Reply With Quote
  #3  
Old   
David Thielen
 
Posts: n/a

Default Re: still having a problem with HTML AlternateView in mail message - 10-08-2009 , 11:52 AM



On Thu, 08 Oct 2009 08:57:12 GMT, jialge (AT) online (DOT) microsoft.com
("Jialiang Ge [MSFT]") wrote:

Quote:
Hello Dave

(MemoryStream)html.GetReport()).GetBuffer() returns a byte array of the
message. If you do not intend to display the preamble bytes (0xEF, 0xBB,
0xBF), could you remove those bytes from this byte array? For example:

byte[] data = new byte[] { 0xa, 0xb, 0xc, 0xEF, 0xBB, 0xBF,
0x1, 0x2, 0x3 };
List<byte> list = new List<byte>(data.Length);
foreach (byte b in data)
{
if (b != 0xEF && b!= 0xBB && b!= 0xBF)
list.Add(b);
}
byte[] result = list.ToArray();
I tried that - then I got a ? at the beginning. It's like it insists
on putting something there.

??? - thanks - dave

david@at-at-at (AT) windward (DOT) dot.dot.net
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm

Reply With Quote
  #4  
Old   
Jialiang Ge [MSFT]
 
Posts: n/a

Default Re: still having a problem with HTML AlternateView in mail message - 10-12-2009 , 01:38 AM



Hello Dave

What was html.GetReport()).GetBuffer() encoded? Unicode or ASCII? Could it
be that it was encoded in Unicode and removing each character requires
deleting two or three bytes instead of one? For example,

byte[] barr = new byte[] { 0x22, 0x8c, 0x22, 0x8c };
string result = Encoding.Unicode.GetString(barr);

This outputs the chinese characters for "xie xie" (thanks). If we just
remove 0x8c from the byte array, the rest two 0x22 constitute a new unicode
word that does not make sense.

Regards,
Jialiang Ge
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg (AT) microsoft (DOT) com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.