Convert a Document to MHTML and Send It by Email
Contents
[
Hide
]
Aspose.Words can convert any document to the MHTML (Web Archive) format. This makes it convenient to use Aspose.Words and Aspose.Email together. You can load a predefined document in any supported format, such as DOC, OOXML, or RTF, into Aspose.Words, fill it with data, save the resulting document as MHTML, and then send it by e-mail using Aspose.Email.
The following code example shows how to convert any document to MHTML and send it by email:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
Document doc = new Document(MyDir + "Document.docx"); | |
Stream stream = new MemoryStream(); | |
doc.Save(stream, SaveFormat.Mhtml); | |
// Rewind the stream to the beginning so Aspose.Email can read it. | |
stream.Position = 0; | |
// Create an Aspose.Email MIME email message from the stream. | |
MailMessage message = MailMessage.Load(stream, new MhtmlLoadOptions()); | |
message.From = "your_from@email.com"; | |
message.To = "your_to@email.com"; | |
message.Subject = "Aspose.Words + Aspose.Email MHTML Test Message"; | |
// Send the message using Aspose.Email. | |
SmtpClient client = new SmtpClient(); | |
client.Host = "your_smtp.com"; | |
client.Send(message); |