Solved

c# extracting receive date from .msg file

Posted on 2009-04-14
6
2,673 Views
Last Modified: 2016-12-11
Hi,

I want to write a program which can read an outlook .msg file and extract the recieved date.  

Basically, I will pass in a file location (of the msg file), then the prgram will extract the received date and write it to a text file.
Ultimately I will want to loop through many files but I am fine with how to do this, I just want to get one working first!

Can anyone help me with this project?


Many Thanks,

David
0
Comment
Question by:dcsearle
6 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 24139234
0
 
LVL 1

Author Comment

by:dcsearle
ID: 24139420
Sorry, but I'm not looking to drag and drop a message or anything like that.  I simply want to extract the receieved date from a .msg file.  If I can just get that into a variable it will do.

Thanks anyway.

Any more suggestions?
0
 
LVL 23

Accepted Solution

by:
Stacy Spear earned 250 total points
ID: 24140023
This requires the Outlook object model.
using System;
using Outlook = Microsoft.Office.Interop.Outlook;
 
namespace ExtractFromMSGFile
{
    class Program
    {
        static void Main(string[] args)
        {
            Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
            Outlook._NameSpace nameSpace = app.GetNamespace("MAPI");
            nameSpace.Logon(null, null, false, false);
            Outlook.Folder folder = (Outlook.Folder)app.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDrafts);
            string filename = @"c:\Temp\Email.msg"; 'Change to the name of your msg file
            Outlook.MailItem msg;
            msg = (Outlook.MailItem)app.CreateItemFromTemplate(filename, folder);
            Console.Write("Subject: " + msg.Subject + ". Received:" + msg.ReceivedTime.Date);
 
 
 
        }
    }
}

Open in new window

0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 1

Author Comment

by:dcsearle
ID: 24167188
hi darkstar,

Thanks for this, I have already written a solution using the Aspose.Network object model (i found that our dev team had purchased an enterprise license for this).

However, I have tested your solution and that seems to work perfectly (i had to add a reference to  microsoft.office.interop.outlook).

Can you tell me, will this work on any machine where office is installed?
For a machine which does not have office, do I need to simply copy the relative .dll with my program and reference that instead?

Many Thanks,

David
0
 
LVL 23

Expert Comment

by:Stacy Spear
ID: 24167272
It will work on any machine with Outlook installed. Where not installed, I do believe that if you register the dll, then it would work. However, I've never tested that since I have enterprise licensing, every machine except Exchange servers pretty much have Outlook on them.
0
 

Expert Comment

by:Binu John
ID: 41921903
when we do this operation from a client web browser, this will not opening the message and reading its content.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question