Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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