Solved

c# extracting receive date from .msg file

Posted on 2009-04-14
6
2,757 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
Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

 
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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

696 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