Solved

c# extracting receive date from .msg file

Posted on 2009-04-14
5
2,608 Views
Last Modified: 2013-12-17
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
  • 2
  • 2
5 Comments
 
LVL 69

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
 
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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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 …

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now