Cargar, Ver y Analizar archivos MSG de Outlook utilizando la Biblioteca de Emails C++
Contents
[
Hide
]
Cargando, Viendo y Analizando Archivos MSG
Este tema explica cómo cargar un archivo de mensaje de Microsoft Outlook (*.msg) utilizando la Biblioteca de Análisis de Emails C++.
La clase MapiMessage se utiliza para cargar archivos MSG y proporciona varias funciones estáticas de carga para diferentes escenarios. El siguiente fragmento de código te muestra cómo cargar archivos MSG desde un archivo o desde un stream.
¡Pruébalo!
Analiza archivos de correo electrónico con la gratuita Aplicación de Análisis Aspose.Email.
Cargando Archivos MSG
El siguiente fragmento de código te muestra cómo cargar archivos 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()); | |
} | |
} |
Cargando desde Stream
El siguiente fragmento de código te muestra cómo cargar un archivo desde un stream.
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()); | |
} |