Compare EML Formats in C#
Native and high performance EML message comparison using server-side Aspose.Email for .NET APIs with out the need of Microsoft Office or PDF installation.
How to Compare EML File Using C#
In order to compare EML file, we’ll use
API which is a feature-rich, powerful and easy to use document manipulation API for C# platform. Open
package manager, search for Aspose.Email and install. You may also use the following command from the Package Manager Console.
Command
PM> Install-Package Aspose.Email
Steps for Comparing EML Files in C#
A basic message comparison with
APIs can be done with just a few lines of code to compare Outlook, Gmail, Apple Mail, Thunderbird documents and get difference between two emails.
- Load the two mail files for comparison.
- Get the body content for each mail file.
- Compare using GetMatrix Method.
- List the differences and set the body content.
- Save the file.
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
Compare EML Files - C#
// fileName1 = eml first file to compare
// fileName2 = eml second file to compare
var email1 = MapiHelper.GetMapiMessageFromFile(Path.Combine(Config.Configuration.WorkingDirectory, folderName, fileName1));
var email2 = MapiHelper.GetMapiMessageFromFile(Path.Combine(Config.Configuration.WorkingDirectory, folderName, fileName2));
var body1 = email1.Body.Split(new string[] { " " }, StringSplitOptions.None).SelectMany(SplitOfNewLine).ToArray();
var body2 = email2.Body.Split(new string[] { " " }, StringSplitOptions.None).SelectMany(SplitOfNewLine).ToArray();
var lcsMatrix = GetMatrix(body1, body2, StringComparer.Ordinal);
var list = new List( LSTnode(string))();
ListDiffTreeFromBacktrackMatrix(list, lcsMatrix, body1, body2, StringComparer.Ordinal);
email2.SetBodyContent(BuildBodyDiff(list), Email.Mapi.BodyContentType.Html);
email2.Save(outPath);
About Aspose.Email for .NET API
Aspose.Email is a Microsoft Outlook and Thunderbird formats parsing solution. One can easily create, manipulate, convert email and storage formats such as MSG, EMLX, EML and MHT. Handling of email attachments, customization of message headers and implementation of different network protocols like POP3, IMAP & SMTP to send & receive emails is much easier. Its a standalone API and does not require Microsoft Outlook or any other software installation.Online EML Comparison Live Demos
EML What is EML File Format
EML file format represents email messages saved using Outlook and other relevant applications. Almost all emailing clients support this file format for its compliance with RFC-822 Internet Message Format Standard. Microsoft Outlook is the default software for opening EML message types. EML files can be used for saving to disc as well as sending out to recipients using communication protocols.
Read More