Click here to Skip to main content
Licence CPOL
First Posted 17 Sep 2008
Views 65,479
Downloads 1,700
Bookmarked 45 times

Easily Retrieve Email Information from .EML Files

By | 30 Apr 2010 | Article
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)

About the Author

BillJam11

Software Developer (Senior)
Lockheed Martin Services Inc
United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralThanks PinmemberKayetyusha15:58 3 Aug '11  
GeneralThanks PinmemberMember 39356031:11 25 Jun '10  
GeneralSend Eml File Pinmemberlascuola_marimo6:40 15 Oct '09  
Generaldrag and drop and then read .eml PinmemberIrishWizKid7:34 18 Jul '09  
GeneralRe: drag and drop and then read .eml PinmemberBillJam112:49 20 Jul '09  
GeneralMy vote of 2 Pinmembergfoidl0:01 12 Jun '09  
GeneralRe: My vote of 2 PinmemberBillJam1112:42 19 Apr '10  
QuestionHow can you create an EML file Pinmembertreb0698:27 10 Mar '09  
AnswerRe: How can you create an EML file PinmemberBillJam1112:12 10 Mar '09  
GeneralRe: How can you create an EML file PinmemberGolden102422:46 29 Mar '09  
GeneralRe: How can you create an EML file PinmemberKalzon119:45 8 Sep '09  
GeneralGreat! Pinmemberdextrous111:37 19 Feb '09  
QuestionHow to extract attchments PinmemberDharmeshChauhan2:00 5 Nov '08  
AnswerRe: How to extract attchments PinmemberBillJam113:57 5 Nov '08  
AnswerRe: How to extract attchments Pinmemberyetibrain14:52 17 Mar '09  
GeneralRe: How to extract attchments PinmemberIrishWizKid20:43 15 Jul '09  
GeneralRe: How to extract attchments PinmemberBillJam112:46 16 Jul '09  
GeneralRe: How to extract attchments PinmemberBroxCJ7:36 10 Aug '09  
GeneralMessage when using the EML Class PinmemberMember 23322535:32 9 Oct '08  
GeneralRe: Message when using the EML Class PinmemberBillJam115:59 9 Oct '08  
GeneralRe: Message when using the EML Class PinmemberBillJam116:20 9 Oct '08  
GeneralRe: Message when using the EML Class Pinmemberyetibrain14:42 17 Mar '09  
QuestionHow about .msg Pinmemberdbujak8:32 19 Sep '08  
AnswerRe: How about .msg Pinmemberphilmee958:07 22 Sep '08  
GeneralRe: How about .msg PinmemberBillJam115:52 9 Oct '08  

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.

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