PNG JPG BMP TIFF EML
Aspose.Email  for .NET

Parse EML Files in C#

An EML file parsing solution for .NET applications without using Microsoft Outlook or third-party dependencies.

 

Extract and Parse EML Files in C#

Aspose.Email for .NET is a C# library that enables developers to handle various email formats, including EML. It provides a powerful API for extracting and parsing EML files, enabling developers to process email content, headers, attachments, and metadata in .NET applications. These features are essential for applications dealing with email processing, such as archiving, analytics, or automated email workflows.

Aspose.Email Key Features for Parsing Emails

  • Load EML files and extract their content, including sender details, recipients, subject, and message body.

  • Extract headers containing essential metadata, such as routing and thread information.

  • Extract email body content: get plain text body (simple representation of the body) or get HTML body as plain text (including hyperlinks).

  • Extract attachments: save attachments for compliance or storage or process attached files for further analysis.

  • Retrieve inline images embedded in content for rich-media processing.

  • Search for specific content in emails by keywords or patterns using the body and header properties.

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:

  1. Open your project in Visual Studio.

  2. Navigate to Tools > NuGet Package Manager > Manage NuGet Packages for Solution.

  3. Search for “Aspose.Email” in the NuGet Package Manager.

  4. 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 EML Files in C#

A basic message parsing with Aspose.Email for .NET APIs can be done with just few lines of code.

  1. Load the email message into a MailMessage object using the Load method with EmlLoadOptions .
  2. Display essential email details: sender, recipient, and subject information.
  3. Retrieve the plain text message body and print it.
  4. Extract and display HTML body as plain text with URLs.
  5. Extract and display HTML body as plain text without URLs.
  6. Decode and print specific email headers (e.g., Thread-Topic).

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 EML Files - C#

// Load the email message into the MailMessage instance
MailMessage message = MailMessage.Load(dataDir + "sample.eml", new EmlLoadOptions());

// Display sender, recipient, and subject information
Console.WriteLine("From: " + message.From);
Console.WriteLine("To: " + message.To);
Console.WriteLine("Subject: " + message.Subject);

// Extract and display plain text body
Console.WriteLine("Plain Text Body:");
Console.WriteLine(message.Body);

// Extract and display HTML body as plain text (with URLs)
string bodyWithUrls = message.GetHtmlBodyText(true);
Console.WriteLine("HTML Body (with URLs):");
Console.WriteLine(bodyWithUrls);

// Extract and display HTML body as plain text (without URLs)
string bodyWithoutUrls = message.GetHtmlBodyText(false);
Console.WriteLine("HTML Body (without URLs):");
Console.WriteLine(bodyWithoutUrls);

// Retrieve and decode a specific email header (e.g., Thread-Topic)
string decodedHeaderValue = message.Headers.GetDecodedValue("Thread-Topic");
Console.WriteLine("Decoded Header (Thread-Topic):");
Console.WriteLine(decodedHeaderValue);
 
  • About Aspose.Email for .NET

    Experience the convenience of parsing EML files in your .NET applications with Aspose.Email. 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 designed to handle complex email-related operations with high performance and minimal coding effort which makes it a go-to choice for .NET developers seeking efficient and reliable email integration. With support for a wide range of email formats such as EML, MSG, MHT, and more, the API enables their seamless management, including creation, parsing, conversion, receiving, sending, and more.

    Online EML Parser Live Demos

    Other Supported Parsing Formats

    Using C#, one can easily parse other formats including:

    MSG (Outlook & Exchange Format)