将文档转换为MHTML并通过电子邮件发送
Contents
[
Hide
]
Aspose.Words可以将任何文档转换为MHTML(Web存档)格式。 这使得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-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); |