Skip to content

Instantly share code, notes, and snippets.

@aspose-com-kb
Last active November 1, 2025 07:48
Show Gist options
  • Save aspose-com-kb/f177ce5e232b2dc9b43f394d021620c1 to your computer and use it in GitHub Desktop.
Save aspose-com-kb/f177ce5e232b2dc9b43f394d021620c1 to your computer and use it in GitHub Desktop.
Convert EML to JPG in Java. For details: https://kb.aspose.com/email/java/convert-eml-to-jpg-in-java/
// Load the source EML file using the MailMessage class
com.aspose.email.MailMessage mailMsg = com.aspose.email.MailMessage.load( "input.eml", emlLoadOptions);
// Create a ByteArrayOutputStream to hold the MHTML data
ByteArrayOutputStream msgStream = new ByteArrayOutputStream();
// Save the MailMessage to MHTML format in the output stream
mailMsg.save(msgStream, com.aspose.email.SaveOptions.getDefaultMhtml());
// Convert the output stream to an input stream for Aspose.Words
java.io.ByteArrayInputStream inputStream = new java.io.ByteArrayInputStream(msgStream.toByteArray());
// Instantiate an instance of the Document class with the MHTML stream
com.aspose.words.Document msgDocument = new com.aspose.words.Document(inputStream);
// Save the document as a JPG image
msgDocument.save("output.jpg", com.aspose.words.SaveFormat.JPEG);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment