Carregar, Visualizar e Analisar arquivo MSG do Outlook usando a Biblioteca de Email C++
Contents
[
Hide
]
Carregando, Visualizando e Analisando Arquivo MSG
Este tópico explica como carregar um arquivo de mensagem do Microsoft Outlook (*.msg) usando a Biblioteca de Análise de Email C++.
A classe MapiMessage é usada para carregar arquivos MSG e fornece várias funções de carregamento estáticas para diferentes cenários. O seguinte trecho de código mostra como carregar arquivos MSG a partir de um arquivo ou de um fluxo.
Experimente!
Analise arquivos de email com o grátis Aspose.Email Parser App.
Carregando Arquivos MSG
O seguinte trecho de código mostra como carregar arquivos MSG.
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
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()); | |
} | |
} |
Carregando de um Fluxo
O seguinte trecho de código mostra como carregar um arquivo de um fluxo.
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
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()); | |
} |