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

Free Support Forum - aspose.com

Saving Plaintext-Mails as HTML

Hello,


I use Apose to load a msg-File from a stream (upload) and I save it as HTML (independent if it is a html, rtf or plaintext mail). That works perfect for me, but I got one issue:

I take a plaintext-message which is windows-encoded and save it as a HTML-file. In the HTML-file the encoding is UTF-16 then.

Is there a possibility to change that? I get problems with the character “ß” which is widely spread in the german language.

Thanks for your help

Andi

Hi Andi,


Thank you for contacting Aspose support team.

I have tried to re-produce this scenario but could not observe the issue. Could you please send a sample MSG file along with the code and output html file? Also please describe in detail the problems with the ß character.


Hi!


I send following Mail als Plaintext:

here is the special „s“ character: ß

<o:p></o:p>

and the result as HTML:


here is the special ?s? character: ?

The problem is the Encoding. My Mail is Windows Encoded and the resulting HTML-File UTF-16. You find the msg-file as attachment.

Best regards,

Andi

Hi Andi,


This sample MSG file is converted to Html format using following code, however no issue is observed in the output Html file. Could you please give it a try using latest version Aspose.Email for Java 6.4.0 and share the feedback with us?

Sample Code

MailMessage mail =
MailMessage.load(
<span style=“font-size:9.0pt;font-family:
“Courier New”;mso-fareast-font-family:“Times New Roman”;color:green”>“test
with ß-1.msg”
);

mail.save(
<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:green”>“test with
ß-1_Java.htm”
, MsgSaveOptions.getDefaultHtml());<o:p></o:p>

Output

here is the special "s" character: ß


I use Aspose.Email for Java 6.3.0.0 at the moment.


I do the following:

MapiMessage mapiMessage = MapiMessage.fromStream(uploadedF.getInputstream());
String body = mapiMessage.getBodyHtml();
// save file als htm-file…

I use MapiMessage because I have to read some other properties out of this message. As soon as I have time to try version 6.4.0 I’ll give it a try.

Best regards,

Andi

Hi Andi,

Please let us know once you are done with your testing. We’ll investigate the issue further in light of your shared information.

Problem still exists with 6.4.0.0


Best Regards

Andi

Hi Andi,

As shared earlier in the sample output with you, we are not able to reproduce this issue at our end. Can you please verify that you have provided us with the right sample file?

I downloaded the file and tried it again - same problem. I upload the file to our server (WebSphere Application Server v 8.0) and looked at the HTML-string:


Copy&Paste from my Code:

MapiMessage mapiMessage = MapiMessage.fromStream(uploadedF.getInputstream());
System.out.println(mapiMessage.getBodyHtml());

The output is the same as before, especially the charset in the header is set to utf-16.

How do you determine the encoding of the message in your code? Do you use any standard-encoding?

Best regards

Hi Andi,

When MapiMessage is used to load a message, it uses the Unicode encoding and that is why all the strings have charset UTF-16. This can’t be changed as it is the API’s default behavior. Please try using the MailMessage as suggested above and let us know if that helps.

Is there a reason why it is encoded in UTF-16 and not in UTF-8?

Hi Andi,

If the source MSG file is saved in Unicode format, then the message’s html body will always contains the utf-16 charset to support the unicode characters. If this is raising some issue at your end, please share the exact scenario with complete sample code that we can further use to assist you. If possible, please share some screenshots of the saved output html file that gives rise to problems due to the utf-16 charset. We’ll investigate the problem at our end for assisting you further.