Загрузка, просмотр и парсинг файла Outlook MSG с использованием библиотеки C++ Email

Загрузка, просмотр и парсинг файла MSG

Эта тема объясняет, как загрузить файл сообщения Microsoft Outlook (*.msg) с использованием библиотеки парсинга электронной почты C++.

Класс MapiMessage используется для загрузки файлов MSG и предоставляет несколько статических функций загрузки для различных сценариев. Следующий фрагмент кода показывает, как загружать файлы MSG из файла или потока.

Загрузка файлов MSG

Следующий фрагмент кода показывает, как загружать файлы MSG.

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());
}
}

Загрузка из потока

Следующий фрагмент кода показывает, как загружать файл из потока.

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());
}