Parse MSG Files in C#
A MSG file parsing solution for .NET applications without using Microsoft Outlook or third-party dependencies.
Extract and Parse MSG Files in C#
Aspose.Email for .NET is a C# library that simplifies the processing of email files, including MSG format. Its powerful API allows developers to load and parse Outlook message files to extract their contents, such as the sender, recipients, subject, and message body. These features make it an essential tool for building .NET applications requiring email processing, like archiving, analysis, or automated workflows.
API Features for Parsing MSG Files
Load MSG files from disk.
Extract sender details: sender’s name and other attributes.
Retrieve subject and body.
Handle recipients: access the collection of recipients and their attributes, such as name, email address, and recipient type.
Iterate over recipients to extract detailed information about each recipient.
Install the C# API
To start coding, ensure that the API is installed in your project. You can add the API via NuGet Package Manager in Visual Studio:
Open your project in Visual Studio.
Navigate to Tools > NuGet Package Manager > Manage NuGet Packages for Solution.
Search for “Aspose.Email” in the NuGet Package Manager.
Select the package and click Install.
Alternatively, you can install it using the Package Manager Console:
Command
PM> Install-Package Aspose.Email
Once installed, you can start integrating its features into your application.
Steps to Parse MSG Files in C#
A basic message parsing using the API can be done with just few lines of code.
- Load the MSG file into the outlookMessageFile object using the MapiMessage.Load method.
- Extract and display message details:
- Sender’s name
- Subject
- Body
- Recipients
System Requirements
Our APIs are supported on all major platforms and Operating Systems. Before executing the code below, please make sure that you have the following prerequisites on your system.
- Microsoft Windows or a compatible OS with .NET Framework, .NET Core, and Xamarin Platforms
- Development environment like Microsoft Visual Studio
- Aspose.Email for .NET DLL referenced in your project - Install from NuGet using the Download button above
Parse MSG Files - C#
// Instantiate the MapiMessage class to load an MSG file
var outlookMessageFile = MapiMessage.Load(dataDir + "message.msg");
// Display sender's name
Console.WriteLine("Sender Name : " + outlookMessageFile.SenderName);
// Display subject
Console.WriteLine("Subject : " + outlookMessageFile.Subject);
// Display body
Console.WriteLine("Body : " + outlookMessageFile.Body);
// Display recipients information
Console.WriteLine("Recipients : \n");
// Loop through the recipients collection associated with the MapiMessage object
foreach (var rcp in outlookMessageFile.Recipients)
{
// Display recipient email address
Console.WriteLine("Email : " + rcp.EmailAddress);
// Display recipient name
Console.WriteLine("Name : " + rcp.DisplayName);
// Display recipient type
Console.WriteLine("Recipient Type : " + rcp.RecipientType);
}
About Aspose.Email C# API
Experience the convenience of parsing MSG files in your .NET applications with an advanced .NET API. Download the free trial and explore the powerful features today. Explore the documentation for in-depth guidance or try the complete examples on GitHub.
The C# library is a comprehensive solution for handling email files and operations within .NET applications. Its high-performance API streamlines complex tasks, providing developers with an efficient way to integrate email functionality into their projects. Supporting various formats, including MSG, EML, MHT, and more, Aspose.Email facilitates seamless management of emails—from parsing and conversion to sending, receiving, and beyond—empowering developers to build feature-rich, reliable email-enabled applications with ease.
Online MSG Parser Live Demos
Other Supported Parsing Formats
Using C#, one can easily parse other formats including: