Convert a Word Document to MHTML and Outlook MSG Format in Android

This technical tip explains how Java developers can Convert Documents to MHTML & then to Outlook MSG inside Android Applications. Aspose.Words allows you to save any document to MHTML (Web Archive) format. This makes it very easy to use Aspose.Words and Aspose.Email 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.Email.

Code samples shows how to save any document from Aspose.Words as MHTML and create a Outlook MSG file from it using Aspose.Email.

// Load the document into Aspose.Words.
String srcFileName = dataDir + "DinnerInvitationDemo.doc";
Document doc = new Document(srcFileName);

// Save to an output stream in MHTML format.
ByteArrayOutputStreamoutputStream = new ByteArrayOutputStream();, SaveFormat.MHTML);

// Load the MHTML stream back into an input stream for use with Aspose.Email.
ByteArrayInputStreaminputStream = new ByteArrayInputStream(outputStream.toByteArray());

// Create an Aspose.Email MIME email message from the stream.
MailMessage message = MailMessage.load(inputStream, MessageFormat.getMht());
message.setFrom(new MailAddress(""));
message.setSubject("Aspose.Words + Aspose.Email MHTML Test Message");

// Save the message in Outlook MSG format. + "Message Out.msg", MailMessageSaveType.getOutlookMessageFormat());