We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Opening HTMLBody in Aspose.Words : encoding problem

Hi,

Look at the email attached. If I want to open the HTMLBody of the email with Aspose.Words, I first need to decode the HTMLBody. Aspose.network email object have information about the body encoding. The property is

Message.BodyEncoding

If this property is null, there is another property witch is

Message.PreferredTextEncoding

.

So, to decode the body, here is what I do to find the correct encoder to use :

Encoding en = Encoding.Default;

if (email.Message.PreferredTextEncoding != null) { en = email.Message.PreferredTextEncoding; }

if (email.Message.BodyEncoding != null) { en = email.Message.BodyEncoding; }

byte[] html = en.GetBytes(email.Message.HtmlBody);

MemoryStream ms = new MemoryStream(html);

LoadOptions lo = new LoadOptions();

lo.LoadFormat =

LoadFormat.Html;

Document doc = new Document(ms, lo);

.

For the attached email : bodyencoding is null and preferedTextEncoding is the one detailed in the attached picture. But if I use the preferedTextEncoding then the docx file created with Aspose.Words contains stange characters.

So here is my question : how do I know witch encoding to use to get the correct text in Aspose.words?

Regards,

Hi,

Thank you for inquiry.

Your code seems to be right and it is also working correctly with the latest versions of Aspose.Network for .NET 6.8 and Aspose.Words for .NET 10.4. Please try the latest versions and see if you still face any issue.