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
Solved

c# extracting receive date from .msg file

Posted on 2009-04-14
6
2,690 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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel macro : save an outlook 2010 mail message to a folder 4 36
jquery tab header text 1 22
abstract class C# 1 31
Groupbox Control ? 2 17
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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 …

808 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