Read the complete article on how to convert EML or MSG Emails to PDF in Java: https://blog.aspose.com/2022/03/22/convert-eml-msg-emails-to-pdf-in-java/
Last active
March 22, 2022 14:29
Convert EML and MSG Emails to PDF in java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load email | |
FileInputStream fstream=new FileInputStream("email.eml"); | |
MailMessage eml = MailMessage.load(fstream); | |
// Save the Message to output stream in MHTML format | |
ByteArrayOutputStream emlStream = new ByteArrayOutputStream(); | |
eml.save(emlStream, SaveOptions.getDefaultMhtml()); | |
// Load the stream in Word document | |
LoadOptions lo = new LoadOptions(); | |
lo.setLoadFormat(LoadFormat.MHTML); | |
Document doc = new Document(new ByteArrayInputStream(emlStream.toByteArray()), lo); | |
// Save to disc | |
doc.save("converted.Pdf", SaveFormat.PDF); | |
// Or save to stream | |
ByteArrayOutputStream foStream = new ByteArrayOutputStream(); | |
doc.save(foStream, SaveFormat.PDF); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment