How to set the charset for a html email?

Hello.

How can we set the charset for a email containing html? If you look at AlternateViews of the Message-object, there are fields containing the content type (i.e. text/html) and the Content-Transfer-Encoding (i.e. quoted-printable). But we cannot find a way to set the desired character set. We are creating a mht file using the Save-method of the Message-object and have to set this charset manually.

An example:
--------_=_NextPart_001_03B8FDDA.E576EB49
Content-Type: text/html;
charset=utf-8 *
Content-Transfer-Encoding: quoted-printable

how to set *?

It seems, that aspose networks determines the charset by analyzing the content (the html). But in our case this is no passable way because then we have problems with german umlaute.

The problem in more detail:
If you open a mht file using a browser, the browser determines the charset using charset attribute from the meta-tag in the html. But in our case Aspose encodes the content wrongly using iso-8859-1. So there is a mismatch between the encoded content and the view encoding. Hence we have to set the charset used by Aspose to encode the content.

I hope I haven´t confused everybody with my explanation.


Thank you.
Andre

Dear Andre,

Thanks for your post.

We are now working on this requirement. I will get back to your and provide a beta dll for your testing shortly.

Have a good day.

Dear Andre,

We have fixed this issue. The hotfix will be released later the day, after normal test pass.

Thanks

Dear Andre,

Please downlaod the hotfix for your testing. let me know if it works:

[http://www.aspose.com/products/Aspose.Network/Releases/Aspose.Network%20hotfix.zip ](https://forum.aspose.com/products/Aspose.Network/Releases/Aspose.Network%20hotfix.zip)

Sample:

MailMessage msg = new MailMessage();
msg.From = "[hello@aspose.com](mailto:hello@aspose.com)";
msg.To = "[recpt1@aspose.com](mailto:recpt1@aspose.com), [recpt2@aspose.com](mailto:recpt2@aspose.com)";
msg.BodyEncoding = System.Text.Encoding.GetEncoding(936);//set the encoding here
msg.HtmlBody = "**呵呵**";
msg.Save(@"test.eml");

Output:

--------_=_NextPart_001_1A4EBD4C.AD202C4F
Content-Type: text/html;
charset=gb2312
Content-Transfer-Encoding: quoted-printable

=BA=C7=BA=C7

Hello.

This fix works for Eml but not for Mht. Can you also fix it for message type Mht?

Thank you.


Use this dll for your usage

[www.aspose.com/products/Aspose.Network/Releases/Aspose.Network3.5.1.9.zip ](https://forum.aspose.com/products/Aspose.Network/Releases/Aspose.Network3.5.1.9.zip)

Thank you.

Now we can set the encoding but the resulting mht does not contain attachments any more (which we had added).


Yes, you are right. It is a new feature in the hotfix.

We removed the attachments if saving to mht format. Do you think it is fine for your requirement? Or perhaps, you want the attachments stay in the mht?

Thanks

At least this should be configurable. We want to create a mht containing all necessary resources. The attachments should be embedded in the file, so we can send the single mht to a user. So the user only needs the mht to open the email.

For this we are manipulating the resulting mht, so the resource links do not link to a resource outside the mht, they link to the resource embedded in the mht. This is achieved by assigning a content id to a resource and by using cid to link the resource. Perhaps you can think about this, it could be a feature, which maybe your API shoud support.

To summarize, yes we need embedded attachments.

Thank you.
Andre

Dear Andre,

We will provide a configrable solution.

Thanks for your information,

please don´t forget this :slight_smile: