5,545,925 members and growing! (17,778 online)
Email Password   helpLost your password?
Languages » C# » General     Intermediate

MsgReader - DLL

By PSI2006

A library which can be used to read Outlook msg-files without outlook
C#, Windows, .NET 1.1, .NETVisual Studio, VS.NET2003, Dev

Posted: 11 Jul 2007
Updated: 16 Jul 2007
Views: 8,176
Bookmarked: 13 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
11 votes for this Article.
Popularity: 3.52 Rating: 3.38 out of 5
1 vote, 9.1%
1
2 votes, 18.2%
2
1 vote, 9.1%
3
0 votes, 0.0%
4
7 votes, 63.6%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article


Introduction

The MsgReader.dll is able to read a Outlook msg-file without having MS Outlook installed. The library is able to read e.g. Subject, message body (also compressed RTF), saving attachments (no msg attachments), ...

It can be use by everybody for non-commercial projects.

Background

To read the OLE-Storage we used the Edanmo.OleStorage.dll. A lot of other codes was derived, ported, ... from code snips we found at the internet.

Using the code

The library was developed with C# and .NET 1.1. Just import it and build your application around. It might contain some failures because this is the first working version we "released". Tests was done with MS Outlook 2003.
For more details check out the MsgReader.chm which contains the whole documentation.

The following code shows a small example how to use the library:

(1) open the selected outlook msg-file

private void btnBrowse_Click(object sender, System.EventArgs e)
{
  this.opnFile.ShowDialog();
  this.txtBoxFile.Text = this.opnFile.FileName;
}


(2) read the to, From, Subject and mail body (plain text & rtf-formated text) property from msg-file and display them

private void btnShow_Click(object sender, System.EventArgs e)
{
  if (this.txtBoxFile.Text != "")
  {
    string[] AttachList;
    string Content = "";
    string path = this.txtBoxFile.Text;
    try
    {
      // First of all you have to create new object
      // the constructor has to take as a argument
      // path to file which we'd like to open
      Msg storage = new Msg(path);
                    
      this.txtBoxTo.Text = storage.GetToProperty();
      this.txtBoxFrom.Text = storage.GetFromProperty();
      this.txtBoxSub.Text = storage.GetSubjectProperty();
      this.txtBoxBody.Text = storage.GetBodyText();
                    
      storage.GetAttachmentList(out AttachList);
                    
      Content = storage.GetBodyRtfText();
      this.RTFBox.TextRTF = addAttachmentsToRTF(Content, AttachList);
      storage.Close();
    }
    catch
    {
      // can not open file
    }
  }
}

(3) this function is adding the windows file type icons of the attachments and the attachments name to the RTF-Body. Only in case the attachments was originally "attached" to a RTF or HTML body the icon will be displayed in the RTF-Body because in case of plain-text mails no attachments rendering position is defined !

private string addAttachmentsToRTF(string RTFBody, string[] attchList)
{
  int lastIndex = 0;
  WMETA8 wmeta8;
  String dummy;

  if (RTFBody.Length > 13) 
  {
    for (int i=0; i<attchList.Length; i++)
    {
      lastIndex = RTFBody.IndexOf("\\objattph\\'20", lastIndex);
      if (lastIndex > 0) 
      {
        RTFBody = RTFBody.Remove(lastIndex, 13);
        wmeta8 = new WMETA8(this.RTFBox.CreateGraphics());
        dummy = attchList[i];
        if (dummy.Length > 15) 
        {
          dummy = "<" + dummy.Substring(0,13) + "..>";
        }
        else 
        {
          dummy = " <" + dummy + ">";
        }
        RTFBody = RTFBody.Insert(lastIndex, (wmeta8.getRTFIcon(attchList[i]) + "{\\fs16 " + dummy +"}"));
      }
      else break;
    }
  }
            
  return RTFBody;
}

The complete Visual Studio project can be also downloaded (TestofMsgReaderDll.zip).

Screenshot - Sample_picture.jpg

Points of Interest

More details, news, updates also regarding the MsgViewer-Application and the DLL can be found at msgviewer.blogspot.com

History

No History yet - there might be some updates in the future

12.7. - picture of the sample application added
17.7. - sorry for the delay - we had some trouble with the upload. Today I added the new DLL-Project (done with VS Studio .Net 2003) and the full library documentation

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

PSI2006



Location: Japan Japan

Other popular C# articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralJust a little bug ?membergantoissylvain@hotmail.com7:46 4 Jun '08  
GeneralWhere to get latest release?memberBilal Haidar3:15 5 May '08  
GeneralWhere is the source codememberDewey22:24 12 Jul '07  
GeneralRe: Where is the source codememberPSI200622:25 16 Jul '07  
GeneralScreenshotmemberMichael Sync23:34 11 Jul '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 16 Jul 2007
Editor:
Copyright 2007 by PSI2006
Everything else Copyright © CodeProject, 1999-2008
Web16 | Advertise on the Code Project