Solved

c# extracting receive date from .msg file

Posted on 2009-04-14
6
2,727 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Create Professional Looking Email Signatures

Create "Professional HTML Email Signatures" with ease.
7 Day Money Back Guarantee if not 100% Satisfied.
Affordable - Try it out for 7 Days Totally Risk Free.
Installers provided for over 45 Email clients.
Both Windows & MAC Supported.
Highly Recommended!

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
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…

732 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