I have a directory of .eml files that contain email conversations. Is there a recommended approach in C# of parsing files of this type?
You can open EML files with a variety of email programs, such as Microsoft Outlook (Windows), Apple Mail (macOS), and Mozilla Thunderbird (multiplatform).
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.
message/rfc822 ("encapsulated message") works, at least with ReactDropzone. That string is what's reported as Type when an . eml file is dropped. (YMMV.)
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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With