Chuyển Đổi Tài liệu thành MHTML Và Gửi Qua Email
Contents
[
Hide
]
Aspose.Words có thể chuyển đổi bất kỳ tài liệu nào sang định dạng MHTML (Lưu Trữ Web). Điều này làm cho nó thuận tiện để sử dụng Aspose.Words và Aspose.Email
cùng nhau. Bạn có thể tải một 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, lưu tài liệu kết quả dưới dạng MHTML, sau đó gửi 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 thành MHTML và gửi qua 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-C | |
// Load the document into Aspose.Words. | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Test File (docx).docx"); | |
// Save into a memory stream in MHTML format. | |
System::SharedPtr<System::IO::MemoryStream> stream = System::MakeObject<System::IO::MemoryStream>(); | |
doc->Save(stream, SaveFormat::Mhtml); | |
// Rewind the stream to the beginning so Aspose.Email can read it. | |
stream->set_Position(0); | |
// Create an Aspose.Email MIME email message from the stream. | |
System::SharedPtr<Aspose::Email::MailMessage > message = System::MakeObject<Aspose::Email::MailMessage>(); | |
message->Load(stream, System::MakeObject<Aspose::Email::MhtmlLoadOptions>()); | |
message->set_From(u"sender@sender.com"); | |
message->get_To()->Add(u"receiver@gmail.com"); | |
message->set_Subject(u"Aspose.Words + Aspose.Email MHTML Test Message"); | |
// Send the message using Aspose.Email | |
System::SharedPtr<Aspose::Email::Clients::Smtp::SmtpClient> client = System::MakeObject<Aspose::Email::Clients::Smtp::SmtpClient>(); | |
client->set_Host(u"mail.server.com"); | |
client->set_Username(u"username"); | |
client->set_Password(u"password"); | |
client->set_Port(587); | |
client->Send(message); |