Last active
June 4, 2021 17:07
-
-
Save aspose-com-gists/2d7aa51be98b9bffef2c2cf0a4333e5a to your computer and use it in GitHub Desktop.
Send Word Document in Email Body using C++
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
Send Word Document in Email Body using C++ |
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
// Directory paths. | |
System::String sourceDataDir = u"SourceDirectory\\"; | |
System::String outputDataDir = u"OutputDirectory\\"; | |
// Load the Word document using Aspose.Words Document class. | |
System::SharedPtr<Aspose::Words::Document> doc = System::MakeObject<Aspose::Words::Document>(sourceDataDir + u"Sample 1.docx"); | |
// Save the document into the MemoryStream 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 instance of the MailMessage class | |
System::SharedPtr<Aspose::Email::MailMessage> message = MailMessage::Load(stream, System::MakeObject<Aspose::Email::MhtmlLoadOptions>()); | |
// Set From Email Address | |
message->set_From(u"your_from@email.com"); | |
// Set To Email Address | |
message->set_To(u"your_to@email.com"); | |
// Set Email Subject | |
message->set_Subject(u"Aspose.Words + Aspose.Email MHTML Test Message"); | |
// Create an instance of the SmtpClient class | |
System::SharedPtr<Aspose::Email::Clients::Smtp::SmtpClient> client = System::MakeObject<Aspose::Email::Clients::Smtp::SmtpClient>(); | |
// Set the Host e.g: smtp.gmail.com | |
client->set_Host(u"your_smtp.com"); | |
// Set the Email Address | |
client->set_Username(u"your_email@email.com"); | |
// Set the Password | |
client->set_Password(u"your_password"); | |
// Set the Port | |
client->set_Port(587); | |
// Set the Security Options | |
client->set_SecurityOptions(SecurityOptions::SSLExplicit); | |
// Send the Email Message | |
client->Send(message); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment