Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommendations on parsing .eml files in C#

Tags:

c#

eml

I have a directory of .eml files that contain email conversations. Is there a recommended approach in C# of parsing files of this type?

like image 246
adeel825 Avatar asked Jun 01 '09 19:06

adeel825


People also ask

What programs can read EML files?

You can open EML files with a variety of email programs, such as Microsoft Outlook (Windows), Apple Mail (macOS), and Mozilla Thunderbird (multiplatform).

Can EML files be malicious?

eml file to a traditional, clean email. The email itself has no malicious links, and though it can be seen by some experienced users as what looks like an invoice fraud attack, it's not instantly apparent. The content of the email bypasses most scanners.

What is the MIME type for EML?

message/rfc822 ("encapsulated message") works, at least with ReactDropzone. That string is what's reported as Type when an . eml file is dropped. (YMMV.)


1 Answers

Added August 2017: Check out MimeKit: https://github.com/jstedfast/MimeKit. It supports .NET Standard, so will run cross-platform.

Original answer: I posted a sample project to illustrate this answer to Github

The CDO COM DLL is part of Windows/IIS and can be referenced in .net. It will provide accurate parsing and a nice object model. Use it in conjuction with a reference to ADODB.DLL.

public CDO.Message LoadEmlFromFile(String emlFileName) {     CDO.Message msg = new CDO.MessageClass();     ADODB.Stream stream = new ADODB.StreamClass();      stream.Open(Type.Missing, ADODB.ConnectModeEnum.adModeUnknown, ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, String.Empty, String.Empty);     stream.LoadFromFile(emlFileName);     stream.Flush();     msg.DataSource.OpenObject(stream, "_Stream");     msg.DataSource.Save();      stream.Close();     return msg; } 
like image 195
Ries Vriend Avatar answered Sep 27 '22 17:09

Ries Vriend