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

Free Support Forum - aspose.com

Some characters cannot be rendered correctly in result of saving from msg in to html

Hi there


We are working on saving .msg file into HTML format.

And here is our code for test:

byte[] msgContent;
msgContent = IOUtils.toByteArray(new FileInputStream(“mailTest.msg”));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
MailMessage msg = MailMessage.load(new ByteArrayInputStream(msgContent));
HtmlSaveOptions saveOps = new HtmlSaveOptions();
saveOps.setCheckBodyContentEncoding(true);
saveOps.setEmbedResources(true);
saveOps.setMailMessageSaveType(MailMessageSaveType.getHtmlFormat());

msg.save(baos, saveOps);
IoUtil.write(new FileOutputStream(“result.html”), baos.toByteArray());

Please also check the input file and output file in the attachment.
Some characters in the result are not rendered correctly.

Is there some option to fix this?


Craig

Hi Craig,

Thank you for contacting Aspose support team.

Please try to specify the text encoding using MsgLoadOptions.setPrefferedTextEncoding for all the characters to be recognized. Please see sample code below,

byte[] msgContent;
msgContent = IOUtils.toByteArray(
new FileInputStream("mailTest.msg"));
ByteArrayOutputStream baos =
new ByteArrayOutputStream();

MsgLoadOptions msgLoadOpt =
new MsgLoadOptions();
msgLoadOpt.setPrefferedTextEncoding(Charset.forName(
"UTF-8"));
MailMessage msg = MailMessage.load(
new ByteArrayInputStream(msgContent), msgLoadOpt);

HtmlSaveOptions saveOps =
new HtmlSaveOptions();
saveOps.setCheckBodyContentEncoding(
true);
saveOps.setEmbedResources(
true);
saveOps.setMailMessageSaveType(MailMessageSaveType.getHtmlFormat());

msg.save(
"result.html", saveOps);


Please try the above code at your end and let us know your feedback.

Hi Maria.Shahid


Thanks for your information.
This option works :slight_smile:

Craig

You are welcome. Please feel free to write back to us in case of any further query.