Emails are a primary source of communication over the internet. You might find yourself in scenarios where you want your applications to read EML and MSG files and add their contents to some file or perform some other operation on them. To that end, this article will teach you how to read email messages using C++.
- C++ API for Reading Email Messages
- Read Email Messages using C++
- Extract Header Information from Email Messages
- Decode Email Message Header Values
- Get a Free License
C++ API for Reading Email Messages
Aspose.Email for C++ is a native C++ library for creating, manipulating, and sending emails without requiring Microsoft Outlook to be installed. The API also supports reading EML and MSG email files. You can either install the API through NuGet or download it directly from the Downloads section.
PM> Install-Package Aspose.Email.Cpp
Read Email Messages using C++
The following are the steps to read email messages.
- Load the email file using the MailMessage class.
- Read the content of the email using the MailMessage->get_From(), MailMessage->get_To(), MailMessage->get_Subject(), MailMessage->get_Body(), etc. methods.
The following is the sample code to read email messages using C++.
Extract Header Information from Email Messages
The following are the steps to extract header information from email messages.
- Load the email file using the MailMessage class.
- Get the header enumerator using the MailMessage->get_Headers()->GetEnumerator() method.
- Loop through the headers and retrieve the header using the MailMessage->get_Headers()->Get (int32_t index) method.
The following is the sample code to extract header information from email messages using C++.
Decode Email Message Header Values
The following are the steps to decode header values in email messages.
- Load the email file using the MailMessage class.
- Decode the header’s value using the MailMessage->get_Headers()->GetDecodedValue (System::String name) method.
The following is the sample code to decode header values in email messages using C++.
Get a Free License
You can try the API without evaluation limitations by requesting a free temporary license.
Live Demo
Conclusion
In this article, you have learned how to read email messages using C++. Specifically, you have learned how to read the email’s content and header information. You have also seen how to decode header values using Aspose.Email for C++ API. In addition to reading email messages, the API provides a lot more features for working with emails. You can explore the API in detail by visiting the official documentation. If you have any questions, please feel free to reach us on our free support forum.