Chuyển đổi tài liệu sang MHTML và gửi nó qua email
Aspose.Words có thể chuyển đổi bất kỳ tài liệu nào sang định dạng MHTML (Web Archive). Điều này giúp thuận tiện khi sử dụng Aspose.Words và Aspose.Email
cùng nhau. Bạn có thể tải tài liệu được xác định trước ở bất kỳ định dạng được hỗ trợ nào, chẳng hạn như DOC, OOXML hoặc RTF, vào Aspose.Words, điền dữ liệu vào đó, lưu tài liệu kết quả dưới dạng MHTML rồi gửi tài liệu đó qua e-mail bằng Aspose.Email
.
Ví dụ mã sau đây cho thấy cách chuyển đổi bất kỳ tài liệu nào sang MHTML và gửi nó qua email:
// 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); |