Recommendations on Parsing .Eml Files in C#

Is it possible to read .eml files in .net

Yes you can. They are just regular text files, nothing fancy.

This is what an eml file looks like on the inside

X-Sender: somewhere@google.com
X-Receiver: somewhere@google.com
MIME-Version: 1.0
From: somewhere@google.com
To: somewhere@google.com
Date: 7 Jun 2009 18:58:01 -0400
Subject: From someone you know
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable

This is the body

Retrieve Email Information from .EML Files

Refer Following link urgently:

http://www.codeproject.com/Articles/76607/Easily-Retrieve-Email-Information-from-EML-Files-R

protected CDO.Message ReadMessage(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();
return msg;
}

You can also get help for elm parsing from:

http://blog.onderweg.eu/2010/12/parsing-eml-files-in-c/

This is also useful tutorial:

http://www.emailarchitect.net/eagetmail/kb/csharp.aspx?cat=18

Saving emails to .eml file using specifiedPickupDirectory creates double decimal points in email body

As I understand it, this is to be expected as the file produced is not supposed to be a straight copy but rather follow the rfc822 spec (see http://www.w3.org/Protocols/rfc822/3_Lexical.html).

If you want to compare the file output with your input, then I think you will need to find/write a routine to decode the rfc822 back to plain test.



Related Topics



Leave a reply



Submit