Click here to Skip to main content
11,709,537 members (50,951 online)
Click here to Skip to main content

Easily Retrieve Email Information from .EML Files

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

Introduction

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, 
                          FileAccess.ReadWrite);
EMLReader reader = new EMLReader(fs);
fs.Close();

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).

License

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

Share

About the Author

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

You may also be interested in...

Comments and Discussions

 
QuestionIssue in getting code Pin
Member 107232557-Jun-15 21:24
memberMember 107232557-Jun-15 21:24 
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 
I don't recall as it's been a while since I've looked at this code. I'm not sure how easy it would be to write an EML file with or without an attachment.
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 
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 
GeneralRe: Message when using the EML Class Pin
BillJam119-Oct-08 6:20
memberBillJam119-Oct-08 6:20 
GeneralRe: Message when using the EML Class Pin
yetibrain17-Mar-09 14:42
memberyetibrain17-Mar-09 14:42 
QuestionHow about .msg Pin
dbujak19-Sep-08 8:32
memberdbujak19-Sep-08 8:32 
AnswerRe: How about .msg Pin
philmee9522-Sep-08 8:07
memberphilmee9522-Sep-08 8:07 

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
Web04 | 2.8.150819.1 | Last Updated 30 Apr 2010
Article Copyright 2008 by BillJam11
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid