Email Header Ordering

I am working on replacing our existing logic to convert an email message to a PDF for users to download. In the tool that previously did the conversion the headers were in a particular order:

From
Subject
To
Sent

But with aspose they are coming out as:

From 
To
Sent 
Subject

I wasnt seeing anything in MhtSaveOptions, is there anyother way to get these formatted in the corresponding PDF file as the client wants?

Code:
FileInputStream fstream = new FileInputStream();
MailMessage email = MailMessage.load(fstream);

MhtSaveOptions saveOptions = SaveOptions.getDefaultMhtml();
saveOptions.getFormatTemplates().add(MhtTemplateName.DATE_TIME, "MMMM d, yyyy hh:mm a");

ByteArrayOutputStream emlStream = new ByteArrayOutputStream();
email.save(emlStream, saveOptions);

LoadOptions lo = new LoadOptions();
lo.setLoadFormat(LoadFormat.MHTML);
com.aspose.words.Document doc = new com.aspose.words.Document(new ByteArrayInputStream(emlStream.toByteArray()), lo);
doc.save(outputFilePath, SaveFormat.PDF);

Any example email file should reproduce the issue.

@mstandfuss,

Thanks for contacting us. I like to inform that i have worked with source code. For further investigation can you please share source file in which you observed issue along with generated mhtml file and output file so that we may help you out.

Any example email file should reproduce the issue.

Like stated above this would be any email file, but I have attached an email for you to use in the case that you dont have any.

Sending an Email To Myself.zip (17.3 KB)

@mstandfuss,

I have worked with source file and sample code shared by you. Can you please share your generated result along with generated mhtml file so that i may further investigate to help you out. I have also shared my generated result with you for your kind reference.mm.zip (2.6 KB)

I was incorrect above its coming out as

From
Sent
To
Subject

But it doesnt change they are expecting it in a different order… Is that something that is supported or not?

Not sure why you need it but here is the pdf that the code is outputting when I run that above.
pdf.zip (134.4 KB)

@mstandfuss,

I have observed your following comments.

To us the MHTML generated from MS Outlook and Aspose.Email have similar correct order. Moreover, the PDF that you have shared has identical order. We are sorry for your inconvenience but we are not able to understand your above statement and issue. Can you please elaborate.

From my original post:

Our client wants the headers ordered in such a way, not the way they appear in Outlook. Our current software that we use to do email -> pdf conversions allows us to specify the order that the headers appear. Since we pay for an Aspose license we are trying to get as much of our logic converted over to using Aspose libraries, but we cannot unless we have the ability to order the headers as they appear in an email.

@mstandfuss,

Actually, Aspose.Email provide export to PDF via exporting message to MHTML first and then using Aspose.Words the same MHTML can be exported to PDF. The export of message to MHTML using Aspose.Email and MS Outlook are identical and there seems no issue in that. Please check the two output files for your kind reference as well.

Output.zip (11.1 KB)

I dont think you are understanding, or reading my responses. I dont want the same order as Outlook or anything else, we need it to match our previous tool to keep backwards compatibility. It needs to be in the order listed above numerous times:

From
Subject
To
Sent

All of the examples you have responded with are in the order

From
Sent
To
Subject

Please note the differences. All I am asking for is if there is a way in the Aspose libraries to set that ordering? If there is not I would like to request it. Please do not link or request more examples.

@mstandfuss,

I have understood the ordering of information requirement shared by you. In fact for comparison purpose, I shared with you that Aspose.Email mimics the behavior of MS Outlook in exported MHTML output (Although this is not what you required). I have created an issue with ID EMAILNET-39614 as investigation to observe if your requirement can be fulfilled using Aspose.Email API. This thread has been linked with the issue so that you may be notified once the issue will be addressed.

The issues you have found earlier (filed as EMAILNET-39614) have been fixed in this update.

We use Aspose for Java, but the work item you linked was for .NET. Will it be ported over to Java as well?

@mstandfuss,

We have added a new API method:

MhtSaveOptions.getRenderingHeaders - Gets list of headers for rendering.

You can try following Java code sample:

String fileName = "test1.eml";
MailMessage eml = MailMessage.load(fileName);
MhtSaveOptions opt = SaveOptions.getDefaultMhtml();

eml.save(fileName + "_1.mhtml", opt);

opt.getRenderingHeaders().add(MhtTemplateName.FROM);
opt.getRenderingHeaders().add(MhtTemplateName.SUBJECT);
opt.getRenderingHeaders().add(MhtTemplateName.TO);
opt.getRenderingHeaders().add(MhtTemplateName.SENT);

eml.save(fileName + "_2.mhtml", opt);

opt.getRenderingHeaders().clear();
opt.getRenderingHeaders().add(MhtTemplateName.ATTACHMENTS);
opt.getRenderingHeaders().add(MhtTemplateName.CC);
opt.getRenderingHeaders().add(MhtTemplateName.SUBJECT);

eml.save(fileName + "_3.mhtml", opt);

Awesome thanks we will give that a shot.

@mstandfuss,

You are always welcome.