Java email library - HTML content in body is not consumed

I’m using java library trial version to create a .msg file. Here’s an example of the HTML body content:


<?xml version="1.0" encoding="utf-8"?>

 

Thank you for contacting CSS (Customer Support and Services).

 

This email is to confirm receipt of your request. The above Service Order Ticket has been created and will be processed in a timely manner.

 

If your matter is urgent and requires immediate attention, we suggest that you follow up with a telephone call or reply to this email so we can prioritize your ticket accordingly. (See contact information below)


the resulting email (.msg) is attached. It does not show all the lines. Something to do with style and font attributes in the

tag, i guess.


Any known issues here? Is there a fix?

Thanks!

Hi Magesh,

Thank you for using Aspose.Email API.

I have reproduced the same issue at my end using the latest version of Aspose.Email for Java API and have logged it as EMAILJAVA-33517 in our issue tracking system for further investigation by our Product team. We’ll notify you here once there is some update available about this issue.

Great, thanks for the quick action and response!


I have confirmed that if i remove all the attributes in the

tags, the .msg file gets created correctly.

Hi Magesh,


Thank you for providing feedback. Please feel free to write us back if you have any other query related to Aspose.Email.

We tried the latest version 5.5.


This issue seems to have been fixed, but there’s a new issue. Plain text emails are losing the carriag return / line feed characters. The
converted .msg file shows the entire content in one single continuous line.

Please let us know ETA for the resolution.

Thanks,

Magesh

Hi Magesh,

I have tested the following sample code but could not observe the issue of plain text emails. Could you please give a try to the following sample code and let us know the feedback? If the issue is not resolved yet, please provide us sample code which can be used here to re-produce the scenario. It will help us to provide assistance at the earliest.

MailMessage msg = new MailMessage();
msg.setBody("Hello\r\nThis is next line.");
msg.save("3.msg", SaveOptions.getDefaultMsgUnicode());

Ok, I am now detecting if the content is HTML or Text and calling setBodyHTML() and setBody().


It works for the most part. No problem with Text body now. I still see some HTML content not being accepted by setBodyHtml().

I have attached an example - that file is the content that goes in setBodyHtml().
Please let me know what the issue is.

thanks,
Magesh

Hi Magesh,

I have tried the sample content and observed that these are properly rendered in the message body. Could you please give it a try a and let us know your feedback?

static String readFile(String path, Charset encoding) throws IOException {
    byte[] encoded = Files.readAllBytes(Paths.get(path));
    return new String(encoded, encoding);
}

static void Email_637640_643776() throws IOException {
    //Html Body
    MailMessage msg = new MailMessage();
    msg.isBodyHtml(true);
    String htmlText = readFile("email.txt", StandardCharsets.UTF_8);
    msg.setHtmlBody(htmlText);
    msg.save("4.msg", SaveOptions.getDefaultMsgUnicode());
}

Hi Muhammad,

I tried and still no luck. Code is identical. Could you send me the .msg you generate?


Here’s the code snippet I tried:

MailMessage msg = new MailMessage();
msg.isBodyHtml(true);
byte[] utf8Bytes = body.getBytes(StandardCharsets.UTF_8);
String utf8Str = new String(utf8Bytes, StandardCharsets.UTF_8);
msg.setHtmlBody(utf8Str);
String msgFileName = txtFile.substring(0, txtFile.lastIndexOf(’.’)) + “.msg”;
msg.save(msgFileName, SaveOptions.getDefaultMsgUnicode());

–Magesh

Hi Magesh,


Here the output message is attached for your reference.

Muhammad - great that you are able to get it to work. I even tried to put the text in the code itself instead of reading from the file. Still not working… anything else you can think of?


Here’s some more info. Making the following modifications, I’m able to get that message built, mostly, but in lower case.
1. I converted the entire body string to lower case
message.setHtmlBody(body.toLowerCase())
2. Removed this section of the body string
"

<SPAN style=“FONT-FAMILY: ‘Arial’,‘sans-serif’; FONT-SIZE: 10pt”><?xml version=\"1.0\"?>\n

\n

Do Not Delete{ticketno:[8000273005]}Do Not Delete

\n" +

You think it is because EVAL copy is introducing something that’s causing it to fail? Could you try with the eval copy instead of the licensed version? Please let me know.


Thanks,
Magesh

Hi Magesh,


We have tested this without applying a license as well and the output is fine. No such malfunctioning is assumed here at our end. Could you please get a 30-day temporary license and try this at your end? Please share your feedback with us then.

Hi Muhammad - After changing the dependency, i.e., moving the library to the top of the dependency list, it works.


Thanks,
Magesh

Hi Magesh,


Thank you for sharing your feedback. We are glad to know that your issue is resolved now. Please feel free to write to us if you have any further inquiry related to the API.