Convert HTML to MHTML in Java
Native HTML to MHTML conversion using Java Email library, without needing any additional software.
How to Convert HTML to MHTML Using Java
In order to render HTML to MHTML, we’ll use
API which is a feature-rich, powerful and easy to use conversion API for Java platform. You can download its latest version directly from
and install it within your Maven-based project by adding the following configurations to the pom.xml.
<repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>https://repository.aspose.com/repo/</url> </repository>
<dependency> <groupId>com.aspose</groupId> <artifactId>aspose-email</artifactId> <version>version of aspose-email API</version> <classifier>jdk17</classifier> </dependency>
Steps to Convert HTML to MHTML via Java
Java programmers can easily convert HTML file to MHTML in just a few lines of code.
- Load HTML file with Aspose.Email for Java MailMessage.load.
- Call the save() method.
- Pass the output file path with (MHTML) file extension.
- Open MHTML file in compatible program.
Before running the Java conversion code, make sure that you have the following prerequisites.
- Microsoft Windows or a compatible OS with Java Runtime Environment for JSP/JSF Application and Desktop Applications.
- Get latest version of Aspose.Email for Java directly from Maven .
Convert HTML to MHTML - Java
// load the HTML file to be converted MailMessage message = MailMessage.load("sourceFile.html"); // save HTML as a MHTML message.save("Saved File.mhtml", SaveOptions.getDefaultMhtml());
HTML to MHTML Conversion Live Demos
Other Supported Conversions
You can also convert HTML into many other file formats including few listed below.