How to read received data from MSG Outlook files - without Outlook API?

I need to read material from an Outlook MSG file. I am currently using a class from CodeProject.com to accomplish this, since deploying VSTO and Outlook on the server is not an option.

This class gets To, From, CC, Subject, Body and everything else that I need from the msg file, except for the date information (for example, Received date and Sent date).

There is some (really, really low level) documentation on how to extract material from MSG files on MSDN, but this is a bit beyond the scope of this project and does not mention dates at all.

Ideally, I could have a replacement for the class I'm using now (OutlookStorage.cs in the previously mentioned CodeProject), or slightly modify an existing class. To change, I will need the correct 4-character scroll identifier for the received date. For example, Subject is displayed as PR_SUBJECT = "0037" , and Body is indicated as PR_BOY = "1000" .

+6
email outlook metadata
source share
4 answers

I think the Aspose library will do what you want, well, that it is a third-party library, maybe not the way you want. There are several vbs scripts that get basic information from msg files that can be translated.

+2
source share

If you are using OutlookStorage.cs from CodeProject, add the following:

 private const string PR_RECEIVED_DATE="007D"; private const string PR_RECEIVED_DATE_2 = "0047"; ... /// <summary> /// Gets the date the message was received. /// </summary> public DateTime ReceivedDate { get { if (_dateRevieved == DateTime.MinValue) { string dateMess = this.GetMapiPropertyString(OutlookStorage.PR_RECEIVED_DATE); if (String.IsNullOrEmpty(dateMess)) { dateMess = this.GetMapiPropertyString(OutlookStorage.PR_RECEIVED_DATE_2); } _dateRevieved = ExtractDate(dateMess); } return _dateRevieved; //return ExtractDate(dateMess); } } private DateTime _dateRevieved = DateTime.MinValue; private DateTime ExtractDate(string dateMess) { string matchStr = "Date:"; string[] lines = dateMess.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (string line in lines) { if (line.StartsWith(matchStr)) { string dateStr = line.Substring(matchStr.Length); DateTime response; if (DateTime.TryParse(dateStr, out response)) { return response; } } } return DateTime.MinValue; } 
+7
source share

Got this hint:

 string fullFileName = "c:\message.msg"; DateTime dateRevieved = new DateTime(); StreamReader sr = new StreamReader(fullFileName, Encoding.Default); string full = sr.ReadToEnd(); string date; int iStart; int iLast; string caption; //This -should- handle all manner of screwage //The ONLY way it would not is if someone guessed the -exact- to-the-second //time that they send the message, put it in their subject in the right format while (true) { //not an infinite loop, I swear! caption = "Date:"; if (full.IndexOf("Date:") > -1) { //full shortens with each date is removed string temp = ""; iStart = full.LastIndexOf(caption); temp = full.Remove(0, iStart + caption.Length); full = full.Substring(0, iStart); iLast = temp.IndexOf("\r\n"); if (iLast < 0) { date = temp; } else { date = temp.Substring(0, iLast); } date = date.Trim(); if (date.Contains(subject) || subject.Contains(date)) { continue; //would only happen if someone is trying to screw me } try { dateRevieved = DateTime.Parse(date); //will fail if not a date break; //if not a date breaks out of while loop } catch { continue; //try with a smaller subset of the msg } } else { break; } } 

This is a kind of hack compared to how you can get other things from msg files using something such a wonderful project . Nevertheless, he supported everything that I threw at him, and, as noted, the only way to cheat is to put the exact date to the end in the subject line in the appropriate format.

+1
source share

to combine your two posts, I would suggest the following solution:

To change, I will need the correct 4-character scroll identifier for the received date. For example, Subject is indicated as PR_SUBJECT = "0037", and Body is specified as PR_BOY = "1000".

Find "007D".

Use the method that you placed in the second column of the received data to fix the problem when the same row (date) is inside the object.


I should mention that this method does not seem to work on internal eMails: substg1.0_007Dxxxx-Property does not exist in the mail messages I receive from colleagues.

Here, the date seems to be hidden in substg1.0_0047xxxx.

All the best!

Inno

+1
source share

All Articles