I was investigating the reverse (unpacking an MHTML/EML to files) and while there didn't seem to be a simple Java-based utility to do this, I found the Apache Mime4J libraries to be very useful (and easier than JavaMail).
You can find the code I shared here: How to read or parse MHTML (.mht) files in java
For your case, to build an MHTML, if you can't find anything simpler, approach could be:
- Create a Message object which has a Multipart body.
- Read all files in a folder using Streams, append these as BodyParts of the Multipart with their mime-type (Mime4j includes a Base64 stream encoder/decoder).
- Ensure the references in the html page point to the necessary body parts (may be able to embed their original filename as reference?).
- Write the Message object to mht file or a response stream.