Click here to Skip to main content
11,411,840 members (52,114 online)
Click here to Skip to main content

Easily Retrieve Email Information from .EML Files

, 30 Apr 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
A wrapper C# class that extracts email fields from EML files


This article is not the best way to do this. Please see EML_ReaderEx.aspx for a better way.

I know parsing .EML files is easy enough to do, but here it is in a wrapper class, all nice and tidy. This comes in real handy if you have a service that needs information that is emailed to the box. It has the usual "To", "CC" fields, along with a collection of x-receiver and many other fields. It will give you both plain text and HTML bodies, provided they are in the EML. Dates are converted to DateTime.

Using the Code

To use this class, just get the FileStream for the .EML file and put it in the constructor of the EMLReader class.

FileStream fs = File.Open(sFile, FileMode.Open, 
EMLReader reader = new EMLReader(fs);

Then, you just retrieve the email properties through the properties of the wrapper class.

foreach(string xReceiver in reader.X_Receivers) 
   // do something with xReceiver

I covered all the email fields that I was concerned about, but there may be some that were left out. However, adding support for new fields in EMLReader is fairly straightforward.

Points of Interest

I worked on this at about the same time that I worked on a wrapper class for MSG files. Big difference in difficulty. Where the EML wrapper class maybe took a day to read the spec and get right, the MSG wrapper class took a week. Probably, most of that time was due to the rather large learning curve on understanding Compound Documents and how MSG uses them. What a mess, and all that for such a legacy format. If Microsoft were to do it today, I'm sure it would all be in XML (attachments might make it a little lengthy though).


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior) Lockheed Martin Services Inc
United States United States
No Biography provided

Comments and Discussions

GeneralThanks PinmemberKayetyusha3-Aug-11 16:58 
GeneralThanks PinmemberMember 393560325-Jun-10 2:11 
GeneralSend Eml File Pinmemberlascuola_marimo15-Oct-09 7:40 
Generaldrag and drop and then read .eml PinmemberIrishWizKid18-Jul-09 8:34 
Look for a way to drag and drop from outlook express then use your code to read .eml

any solid working solutions. the net is filled with ideas on this topic but no working examples - c# please
GeneralRe: drag and drop and then read .eml PinmemberBillJam1120-Jul-09 3:49 
GeneralMy vote of 2 Pinmembergfoidl12-Jun-09 1:01 
GeneralRe: My vote of 2 PinmemberBillJam1119-Apr-10 13:42 
QuestionHow can you create an EML file Pinmembertreb06910-Mar-09 9:27 
AnswerRe: How can you create an EML file PinmemberBillJam1110-Mar-09 13:12 
GeneralRe: How can you create an EML file PinmemberGolden102429-Mar-09 23:46 
GeneralRe: How can you create an EML file PinmemberKalzon18-Sep-09 20:45 
GeneralGreat! Pinmemberdextrous119-Feb-09 12:37 
QuestionHow to extract attchments PinmemberDharmeshChauhan5-Nov-08 3:00 
AnswerRe: How to extract attchments PinmemberBillJam115-Nov-08 4:57 
AnswerRe: How to extract attchments Pinmemberyetibrain17-Mar-09 15:52 
GeneralRe: How to extract attchments PinmemberIrishWizKid15-Jul-09 21:43 
GeneralRe: How to extract attchments PinmemberBillJam1116-Jul-09 3:46 
GeneralRe: How to extract attchments PinmemberBroxCJ10-Aug-09 8:36 
GeneralMessage when using the EML Class PinmemberMember 23322539-Oct-08 6:32 
GeneralRe: Message when using the EML Class PinmemberBillJam119-Oct-08 6:59 
GeneralRe: Message when using the EML Class PinmemberBillJam119-Oct-08 7:20 
GeneralRe: Message when using the EML Class Pinmemberyetibrain17-Mar-09 15:42 
QuestionHow about .msg Pinmemberdbujak19-Sep-08 9:32 
AnswerRe: How about .msg Pinmemberphilmee9522-Sep-08 9:07 
GeneralRe: How about .msg PinmemberBillJam119-Oct-08 6:52 
AnswerRe: How about .msg PinmemberBillJam119-Oct-08 7:04 
AnswerRe: How about .msg PinmemberBillJam112-Jun-09 12:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150414.5 | Last Updated 30 Apr 2010
Article Copyright 2008 by BillJam11
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid