You can download the complete source code of the SaveMhtmlAndEmail sample here.
Aspose.Words allows saving any document in MHTML (Web Archive) format. This makes it very easy to use Aspose.Words and Aspose.Network together to generate email messages with rich content. For example, you can load a predefined DOC, OOXML or RTF document into Aspose.Words, fill it with data, save as MHTML and then convert to any mail format supported by Aspose.Network.
Example
Shows how to save any document from Aspose.Words as MHTML and create a Outlook MSG file from it using Aspose.Network.
[Java]
// Load the document into Aspose.Words.
String srcFileName = dataDir + "DinnerInvitationDemo.doc";
Document doc = new Document(srcFileName);
// Save to an output stream in MHTML format.
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
doc.save(outputStream, SaveFormat.MHTML);
// Load the MHTML stream back into an input stream for use with Aspose.Network.
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
// Create an Aspose.Network MIME email message from the stream.
MailMessage message = MailMessage.load(inputStream, MessageFormat.getMht());
message.setFrom(new MailAddress("your_from@email.com"));
message.getTo().add("your_to@email.com");
message.setSubject("Aspose.Words + Aspose.Network MHTML Test Message");
// Save the message in Outlook msg format.
message.save(dataDir + "Message Out.msg", MailMessageSaveType.getOutlookMessageFormat());