Load, View and Parse Outlook MSG file using C++ Email Library
Contents
[
Hide
]
Loading, Viewing and Parsing MSG File
This topic explains how to load a Microsoft Outlook Messagefile (*.msg) using C++ Email Parser Library.
The MapiMessage class is used to load MSG files, and provides several static loading functions for different scenarios. The following code snippet shows you how to load MSG files from file or from stream.
Try it out!
Parse email files with the free Aspose.Email Parser App.
Loading MSG Files
The following code snippet shows you how to load MSG files.
This file contains hidden or 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/kashifiqb/Aspose.Email-for-C | |
// The path to the File directory. | |
System::String dataDir = RunExamples::GetDataDir_Outlook(); | |
// Create an instance of MapiMessage from file | |
System::SharedPtr<MapiMessage> msg = MapiMessage::FromFile(dataDir + L"message.msg"); | |
// Get subject | |
System::Console::WriteLine(System::String(L"Subject:") + msg->get_Subject()); | |
// Get from address | |
System::Console::WriteLine(System::String(L"From:") + msg->get_SenderEmailAddress()); | |
// Get body | |
System::Console::WriteLine(System::String(L"Body") + msg->get_Body()); | |
// Get recipients information | |
System::Console::WriteLine(System::String(L"Recipient: ") + msg->get_Recipients()); | |
// Get attachments | |
{ | |
auto att_enumerator = (msg->get_Attachments())->GetEnumerator(); | |
decltype(att_enumerator->get_Current()) att; | |
while (att_enumerator->MoveNext() && (att = att_enumerator->get_Current(), true)) | |
{ | |
System::Console::Write(System::String(L"Attachment Name: ") + att->get_FileName()); | |
System::Console::Write(System::String(L"Attachment Display Name: ") + att->get_DisplayName()); | |
} | |
} |
Loading from Stream
The following code snippet shows you how to load file from stream.
This file contains hidden or 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/kashifiqb/Aspose.Email-for-C | |
// Create an instance of MapiMessage from file | |
System::ArrayPtr<uint8_t> bytes = System::IO::File::ReadAllBytes(dataDir + L"message.msg"); | |
{ | |
System::SharedPtr<System::IO::MemoryStream> stream = System::MakeObject<System::IO::MemoryStream>(bytes); | |
stream->Seek(0, System::IO::SeekOrigin::Begin); | |
// Create an instance of MapiMessage from file | |
System::SharedPtr<MapiMessage> msg = MapiMessage::FromStream(stream); | |
// Get subject | |
System::Console::WriteLine(System::String(L"Subject:") + msg->get_Subject()); | |
// Get from address | |
System::Console::WriteLine(System::String(L"From:") + msg->get_SenderEmailAddress()); | |
// Get body | |
System::Console::WriteLine(System::String(L"Body") + msg->get_Body()); | |
} |