|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
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
IntroductionThe 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. BackgroundTo 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 codeThe 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. 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; }
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).
Points of InterestMore details, news, updates also regarding the MsgViewer-Application and the DLL can be found at msgviewer.blogspot.com HistoryNo History yet - there might be some updates in the future 12.7. - picture of the sample application added
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||