文書をMHTMLに変換し、電子メールで送信する
Contents
[
Hide
]
Aspose.Wordsは任意の文書をMHTML(Web Archive)形式に変換できます。 これにより、Aspose.WordsとAspose.Email
を一緒に使用すると便利です。 定義済みの文書をDOC、OXML、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); |