将文档转换为 MHTML 并通过电子邮件发送
Contents
[
Hide
]
Aspose.Words 可以将任何文档转换为 MHTML(Web Archive)格式。这使得 Aspose.Words 和 Aspose.Email
一起使用变得很方便。您可以将任何受支持格式(例如 DOC、OOXML 或 RTF)的预定义文档加载到 Aspose.Words 中,填充数据,将生成的文档另存为 MHTML,然后使用 Aspose.Email
通过电子邮件发送。
以下代码示例演示如何将任何文档转换为 MHTML 并通过电子邮件发送:
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); |