Click here to Skip to main content
15,398,850 members
Articles / Programming Languages / C#
Posted 17 Sep 2008


60 bookmarked

Easily Retrieve Email Information from .EML Files

Rate me:
Please Sign up or sign in to vote.
4.37/5 (16 votes)
30 Apr 2010CPOL1 min read
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

QuestionError on DateTime.Parse(saHdr[1]) Pin
Member 1499384315-Nov-20 19:26
MemberMember 1499384315-Nov-20 19:26 
QuestionNice code Pin
_SlowArrow_13-Mar-16 12:52
Member_SlowArrow_13-Mar-16 12:52 
QuestionIssue in getting code Pin
Dipti Dhiman 37-Jun-15 21:24
MemberDipti Dhiman 37-Jun-15 21:24 
AnswerRe: Issue in getting code Pin
Member 1346134412-Oct-17 3:22
MemberMember 1346134412-Oct-17 3:22 
GeneralThanks Pin
Kayetyusha3-Aug-11 15:58
MemberKayetyusha3-Aug-11 15:58 
GeneralThanks Pin
Member 393560325-Jun-10 1:11
MemberMember 393560325-Jun-10 1:11 
GeneralSend Eml File Pin
lascuola_marimo15-Oct-09 6:40
Memberlascuola_marimo15-Oct-09 6:40 
Generaldrag and drop and then read .eml Pin
IrishWizKid18-Jul-09 7:34
MemberIrishWizKid18-Jul-09 7:34 
GeneralRe: drag and drop and then read .eml Pin
BillJam1120-Jul-09 2:49
MemberBillJam1120-Jul-09 2:49 
GeneralMy vote of 2 Pin
gfoidl12-Jun-09 0:01
Membergfoidl12-Jun-09 0:01 
GeneralRe: My vote of 2 Pin
BillJam1119-Apr-10 12:42
MemberBillJam1119-Apr-10 12:42 
QuestionHow can you create an EML file Pin
treb06910-Mar-09 8:27
Membertreb06910-Mar-09 8:27 
AnswerRe: How can you create an EML file Pin
BillJam1110-Mar-09 12:12
MemberBillJam1110-Mar-09 12:12 
GeneralRe: How can you create an EML file Pin
Golden102429-Mar-09 22:46
MemberGolden102429-Mar-09 22:46 
GeneralRe: How can you create an EML file Pin
Kalzon18-Sep-09 19:45
MemberKalzon18-Sep-09 19:45 
GeneralRe: How can you create an EML file Pin
Member 1340592124-Oct-17 0:17
MemberMember 1340592124-Oct-17 0:17 
GeneralGreat! Pin
dextrous119-Feb-09 11:37
Memberdextrous119-Feb-09 11:37 
QuestionHow to extract attchments Pin
DharmeshChauhan5-Nov-08 2:00
MemberDharmeshChauhan5-Nov-08 2:00 
AnswerRe: How to extract attchments Pin
BillJam115-Nov-08 3:57
MemberBillJam115-Nov-08 3:57 
AnswerRe: How to extract attchments Pin
yetibrain17-Mar-09 14:52
Memberyetibrain17-Mar-09 14:52 
GeneralRe: How to extract attchments Pin
IrishWizKid15-Jul-09 20:43
MemberIrishWizKid15-Jul-09 20:43 
GeneralRe: How to extract attchments Pin
BillJam1116-Jul-09 2:46
MemberBillJam1116-Jul-09 2:46 
GeneralRe: How to extract attchments Pin
BroxCJ10-Aug-09 7:36
MemberBroxCJ10-Aug-09 7:36 
GeneralMessage when using the EML Class Pin
Member 23322539-Oct-08 5:32
MemberMember 23322539-Oct-08 5:32 
GeneralRe: Message when using the EML Class Pin
BillJam119-Oct-08 5:59
MemberBillJam119-Oct-08 5:59 

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

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