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

Free Support Forum - aspose.com

Failure converting EML to PDF

Hello guys,


I’m having a problem converting EML files, some of them are converted but the resulting PDF is not the formatted text of the email, instead, it is the “source code” of the email, like this:

Delivered-To: gnc@mcfile.com.br
Received: by 10.50.97.74 with SMTP id dy10csp92152igb;
Mon, 29 Jul 2013 05:04:57 -0700 (PDT)
X-Received: by 10.236.113.176 with SMTP id a36mr26911497yhh.14.1375099497170;
Mon, 29 Jul 2013 05:04:57 -0700 (PDT)
Return-Path: daniel@polisacos.com.br


In attachment I have two examples of very similar emails (the EML and the PDF converted), but one was converted correctly, the other didn’t.

Thank you.

Hi Mario,


Thanks for your inquiry.

I have tested the scenario and have not found the shared issue by using latest version of Aspose.Words and Aspose.Email. I suggest you please use the latest version of Aspose.Words for Java 13.6.0 and Aspose.Email for Java 3.1.0. I have attached the output Pdf file with this post for your kind reference.

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

Hello Tahir,


both Aspose Words and Aspose Email are on my classpath and I’m using this code:

String path = “not converted.eml”;
try {
License license = new License();
license.setLicense(“Aspose.Words.Java.lic”);
Document doc = new Document(path);
doc.save(path + “.pdf”);
} catch (Exception e) {
e.printStackTrace();
}


Is there something more I should be doing?

Thank you.

Hi Mario,


Thanks for your feedback. To convert .Eml to Pdf, first you need to convert .Eml to Mhtml format by using Aspose.Email. Once you have Mhtml file, you can convert it to Pdf by using Aspose.Words.

Please use the following code snippet to convert .eml to pdf. Hope this helps you. Please let us know if you have any more queries.

ByteArrayOutputStream dstStream = new ByteArrayOutputStream();<o:p></o:p>

MailMessage mail = MailMessage.load(MyDir + "not converted.eml");

mail.save(dstStream, MailMessageSaveType.getMHtmlFormat());

ByteArrayInputStream srcStream = new ByteArrayInputStream(dstStream.toByteArray());

Document doc = new Document(srcStream);

doc.save(MyDir + "Out.pdf");

doc.save(MyDir + "Out.docx");