Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/7496eada13a2a2eb4fff1d2e146dd91e to your computer and use it in GitHub Desktop.
Save aspose-com-gists/7496eada13a2a2eb4fff1d2e146dd91e to your computer and use it in GitHub Desktop.
Convert Email Messages to PDF using C++
Convert Email Messages to PDF using C++
// Source email file
System::String sampleFile = u"SourceDirectory\\Message.msg";
// Load email message using file
System::SharedPtr<Aspose::Email::MailMessage> msg = Aspose::Email::MailMessage::Load(sampleFile);
// Create memory stream
System::SharedPtr<System::IO::MemoryStream> stream = System::MakeObject<System::IO::MemoryStream>();
// Save email message into memory stream
msg->Save(stream, Aspose::Email::SaveOptions::get_DefaultMhtml());
// Create load options
System::SharedPtr<Aspose::Words::LoadOptions> loadOptions = System::MakeObject<Aspose::Words::LoadOptions>();
// Set load format
loadOptions->set_LoadFormat(Aspose::Words::LoadFormat::Mhtml);
// Create an instance of Document class and load the MTHML from MemoryStream
System::SharedPtr<Aspose::Words::Document> doc = System::MakeObject<Aspose::Words::Document>(stream, loadOptions);
// Output file path
System::String outputPath = u"OutputDirectory\\email-to-pdf.pdf";
// Save email as PDF
doc->Save(outputPath, Aspose::Words::SaveFormat::Pdf);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment