Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active April 22, 2021 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/92bebfb96a8d9e0a154eca412c107a5d to your computer and use it in GitHub Desktop.
Save aspose-com-gists/92bebfb96a8d9e0a154eca412c107a5d to your computer and use it in GitHub Desktop.
Read Email Messages using C++
Examples for reading Email Messages using C++
// Create MailMessage instance by loading an EML file
System::SharedPtr<MailMessage> message = MailMessage::Load(u"SourceDirectory\\Message.eml", System::MakeObject<EmlLoadOptions>());
// Get decoded value from the header
System::String decodedValue = message->get_Headers()->GetDecodedValue(u"Thread-Topic");
// Print the value
System::Console::WriteLine(decodedValue);
// Create MailMessage instance by loading an EML file
System::SharedPtr<MailMessage> message = MailMessage::Load(u"SourceDirectory\\Message.eml", System::MakeObject<EmlLoadOptions>());
// Print out all the headers
int32_t index = 0;
{
auto header_enumerator = message->get_Headers()->GetEnumerator();
decltype(header_enumerator->get_Current()) header;
while (header_enumerator->MoveNext() && (header = header_enumerator->get_Current(), true))
{
System::Console::Write(header + u" - ");
System::Console::WriteLine(message->get_Headers()->Get(index++));
}
}
// Create MailMessage instance by loading an EML file
System::SharedPtr<MailMessage> message = MailMessage::Load(u"SourceDirectory\\Message.eml", System::MakeObject<EmlLoadOptions>());
// Get the sender info
System::Console::WriteLine(u"From:");
System::Console::WriteLine(message->get_From());
// Get the recipients info
System::Console::WriteLine(u"To:");
System::Console::WriteLine(message->get_To());
// Get the subject
System::Console::WriteLine(u"Subject:");
System::Console::WriteLine(message->get_Subject());
// Get the HTML body
System::Console::WriteLine(u"HtmlBody:");
System::Console::WriteLine(message->get_HtmlBody());
// Get the text body
System::Console::WriteLine(u"TextBody:");
System::Console::WriteLine(message->get_Body());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment