Problem converting e-mail (msg file) to pdf

Hello. I wanted to convert some saved emails files to pdf with the following code but it fails with the attached msg file (it hangs after printing “3”). Code is based in this previous post (I have modified it a bit because of a compilation error).



package asposetest;

import com.aspose.email.MailMessage;
import com.aspose.email.MhtSaveOptions;
import com.aspose.words.Document;
import com.aspose.words.LoadFormat;
import com.aspose.words.LoadOptions;
import com.aspose.words.SaveFormat;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;

<span style=“font-family: “Courier New”; font-size: small;”>public class AsposeTestEmailToPDF {
<span style=“font-family: “Courier New”; font-size: small;”>
private static void EmailToPdf(String emailPath, String dest) throws Exception
{
System.out.println(“1”);
FileInputStream fstream=new FileInputStream(emailPath);
MailMessage eml = MailMessage.load(fstream);
System.out.println(“2”);
//Save the Message to output stream in MHTML format
ByteArrayOutputStream emlStream = new ByteArrayOutputStream();
MhtSaveOptions so = new MhtSaveOptions();
eml.save(emlStream,so);
System.out.println(“3”);
//Load the stream in Word document
LoadOptions lo = new LoadOptions();
lo.setLoadFormat(LoadFormat.MHTML);
Document doc = new Document(new ByteArrayInputStream(emlStream.toByteArray()), lo);
System.out.println(“4”);
//Save to disc
doc.save(dest, SaveFormat.PDF);
System.out.println(“5”);
//or Save to stream
ByteArrayOutputStream foStream = new ByteArrayOutputStream();
doc.save(foStream, SaveFormat.PDF);
System.out.println(“6”);
}

<span style=“font-family: “Courier New”; font-size: small;”> public static void main(String[] args) throws Exception {
EmailToPdf(args[0], args[1]);
}
}

The attached msg file should be ok, I have downloaded it from this previous post.

Hi,

Thank you for contacting Aspose support team.

We have analyzed the sample MSG file and tried to convert it to Mht file using Outlook 2013, however it hangs the outlook and it is not converted to Mht file. It seems that there is some issue in this MSG file, that is why issues are there in the conversion. You may please verify this behavior with outlook and provide us a sample message which is converted to Mht using outlook without any error. We will analyze it and provide assistance accordingly.

Thanks for your answer. Currently I haven’t got another sample file. I will get back to you if I can manage to get another one.

You are welcome.