generating multipart/alternative mails with system.net.mail, "double encapsulation issue"

P

pehelce

Hi,

I' m currently migrating some tools from .NET1 to .NET2.
in the previous version we used a component called FreeSMTP to
generate and send the mails.
Now we use the System.net.mail component.

My problem is that although I enforce the correct encoding
(iso-8859-1), the mails have scrambled characters where the special
caracters are supposed to be (accented letters, scandinavian letters,
german letters and so on).

In short this is what I do (one of the ways, I've bee trying lots of
combinations but it won't do):
---------------------------------------------------------------------------------------------------------------------------------------------------
(msgObj is my MailMessage object)

AlternateView
htmlTextView=AlternateView.CreateAlternateViewFromString(m_Content);
AlternateView
plainTextView=AlternateView.CreateAlternateViewFromString(m_TextContent) ;

msgObj.AlternateViews.Add(plainTextView);
msgObj.AlternateViews.Add(htmlTextView);

msgObj.AlternateViews[0].ContentType.MediaType = "text/plain";
msgObj.AlternateViews[1].ContentType.MediaType = "text/html";

msgObj.AlternateViews[0].TransferEncoding =
System.Net.Mime.TransferEncoding.QuotedPrintable;
msgObj.AlternateViews[1].TransferEncoding =
System.Net.Mime.TransferEncoding.QuotedPrintable;

msgObj.AlternateViews[0].ContentType.CharSet =
System.Text.Encoding.GetEncoding(m_Encoding).WebName;
msgObj.AlternateViews[1].ContentType.CharSet =
System.Text.Encoding.GetEncoding(m_Encoding).WebName;



......then I send It

---------------------------------------------------------------------------------------------------------------------------------------------------


the main difference I see when I compare the mail source generated by
System.net.mail, and freeSMTP
is that in freeSMTP the mail header indicates a multipart/alternative
mail, with a pointer to the part boundaries.
Whereas the .NET version header indicates a multipart/mixed (as if it
were an attachement or a linked resource) with a pointer to a boundary
where I find a description of a multipart/alternative with a pointer
to the text and html boundaries.
I suspect the character recognition issues we've had to be linked to
this "double encapsulation" situation (I think it's also the cause of
another bug, some people getting the mail content as attachments....).

Juste to make it a bit clearer here are the header of the mails..
first one works ok, second is giberish:
OK---------------------------------------------------------------------------------------------------------------------------------------------------

Content-Type: multipart/alternative;
boundary="----=_NextPart_542ab2f3_a829_4407_989d_5e7e35647ef3"

------=_NextPart_542ab2f3_a829_4407_989d_5e7e35647ef3
Content-type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

------=_NextPart_542ab2f3_a829_4407_989d_5e7e35647ef3
Content-type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable


------=_NextPart_542ab2f3_a829_4407_989d_5e7e35647ef3--



KO---------------------------------------------------------------------------------------------------------------------------------------------------


content-type: multipart/mixed; boundary=--
boundary_0_4a9a6aff-3d62-42da-9121-da29bedc1cf6

----boundary_0_4a9a6aff-3d62-42da-9121-da29bedc1cf6
content-type: multipart/alternative; boundary=--
boundary_1_2169a616-120b-4264-8696-050078998bf4

----boundary_1_2169a616-120b-4264-8696-050078998bf4
content-type: text/plain; charset=iso-8859-1
content-transfer-encoding: quoted-printable

----boundary_1_2169a616-120b-4264-8696-050078998bf4
content-type: text/html; charset=iso-8859-1
content-transfer-encoding: quoted-printable


----boundary_1_2169a616-120b-4264-8696-050078998bf4--

----boundary_0_4a9a6aff-3d62-42da-9121-da29bedc1cf6--
---------------------------------------------------------------------------------------------------------------------------------------------------

I've tried clearing the header before sending the mail, and inserting
the correct header, and enforcing a generated boundaries ... doesn't
work, and the mail gets double items in the header ...

If anybody has a clue on how to correct this, I'd be grateful ^_^


Best Regards,

PLC
 
G

Guest

I'm having the same problem, and it's killing us on gmail especially. Did
you find any workarounds?

Hi,

I' m currently migrating some tools from .NET1 to .NET2.
in the previous version we used a component called FreeSMTP to
generate and send the mails.
Now we use the System.net.mail component.

My problem is that although I enforce the correct encoding
(iso-8859-1), the mails have scrambled characters where the special
caracters are supposed to be (accented letters, scandinavian letters,
german letters and so on).

In short this is what I do (one of the ways, I've bee trying lots of
combinations but it won't do):
---------------------------------------------------------------------------------------------------------------------------------------------------
(msgObj is my MailMessage object)

AlternateView
htmlTextView=AlternateView.CreateAlternateViewFromString(m_Content);
AlternateView
plainTextView=AlternateView.CreateAlternateViewFromString(m_TextContent) ;

msgObj.AlternateViews.Add(plainTextView);
msgObj.AlternateViews.Add(htmlTextView);

msgObj.AlternateViews[0].ContentType.MediaType = "text/plain";
msgObj.AlternateViews[1].ContentType.MediaType = "text/html";

msgObj.AlternateViews[0].TransferEncoding =
System.Net.Mime.TransferEncoding.QuotedPrintable;
msgObj.AlternateViews[1].TransferEncoding =
System.Net.Mime.TransferEncoding.QuotedPrintable;

msgObj.AlternateViews[0].ContentType.CharSet =
System.Text.Encoding.GetEncoding(m_Encoding).WebName;
msgObj.AlternateViews[1].ContentType.CharSet =
System.Text.Encoding.GetEncoding(m_Encoding).WebName;



......then I send It

---------------------------------------------------------------------------------------------------------------------------------------------------


the main difference I see when I compare the mail source generated by
System.net.mail, and freeSMTP
is that in freeSMTP the mail header indicates a multipart/alternative
mail, with a pointer to the part boundaries.
Whereas the .NET version header indicates a multipart/mixed (as if it
were an attachement or a linked resource) with a pointer to a boundary
where I find a description of a multipart/alternative with a pointer
to the text and html boundaries.
I suspect the character recognition issues we've had to be linked to
this "double encapsulation" situation (I think it's also the cause of
another bug, some people getting the mail content as attachments....).

Juste to make it a bit clearer here are the header of the mails..
first one works ok, second is giberish:
OK---------------------------------------------------------------------------------------------------------------------------------------------------

Content-Type: multipart/alternative;
boundary="----=_NextPart_542ab2f3_a829_4407_989d_5e7e35647ef3"

------=_NextPart_542ab2f3_a829_4407_989d_5e7e35647ef3
Content-type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

------=_NextPart_542ab2f3_a829_4407_989d_5e7e35647ef3
Content-type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable


------=_NextPart_542ab2f3_a829_4407_989d_5e7e35647ef3--



KO---------------------------------------------------------------------------------------------------------------------------------------------------


content-type: multipart/mixed; boundary=--
boundary_0_4a9a6aff-3d62-42da-9121-da29bedc1cf6

----boundary_0_4a9a6aff-3d62-42da-9121-da29bedc1cf6
content-type: multipart/alternative; boundary=--
boundary_1_2169a616-120b-4264-8696-050078998bf4

----boundary_1_2169a616-120b-4264-8696-050078998bf4
content-type: text/plain; charset=iso-8859-1
content-transfer-encoding: quoted-printable

----boundary_1_2169a616-120b-4264-8696-050078998bf4
content-type: text/html; charset=iso-8859-1
content-transfer-encoding: quoted-printable


----boundary_1_2169a616-120b-4264-8696-050078998bf4--

----boundary_0_4a9a6aff-3d62-42da-9121-da29bedc1cf6--
---------------------------------------------------------------------------------------------------------------------------------------------------

I've tried clearing the header before sending the mail, and inserting
the correct header, and enforcing a generated boundaries ... doesn't
work, and the mail gets double items in the header ...

If anybody has a clue on how to correct this, I'd be grateful ^_^


Best Regards,

PLC
 
Top