none
How to get the properties of the .msg file? RRS feed

  • Question

  • Hello everyone,

    When I double-click a .msg file to open it and then reply to sender, how to get the properties of the original message, such as received time, size, etc.? Thanks in advance.

    Monday, February 20, 2017 1:14 PM

Answers

  • When you double click on an MSG file, Outlook imports it into the default message store. You never deal directly with the MSG file itself. So there is really no difference between the two cases.

    You cannot assume that the currently selected message is the one the user is replying to. What is the message was first opened for reading and displayed in an inspector? Worse that that, you can have multiple inspectors open at a time.

    What you need to do is track the Explorer.SelectionChange event and set up event handlers on the selected items. You also need to subscribe to the Application.Inspectors.NewInspector event and set up event sink on the Inspector.CurentItem object.

    You can then use MailItem.Reply/ReplyAll/Forward events to access the newly created response as well as the original message.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Proposed as answer by Eugene Astafiev Monday, February 20, 2017 5:45 PM
    • Marked as answer by leon1526 Wednesday, February 22, 2017 11:20 AM
    Monday, February 20, 2017 4:01 PM
  • Hi Leon,

    Yes, you can get the properties. When you click on the .msg file on the disk and Outlook runs a new inspector window is displayed for the .msg file. The NewInspector event of the Inspectors class is fired whenever a new inspector window is opened, either as a result of user action or through program code. Be aware, you need to wait for the first Activate event of the Inspector class to get an Outlook item opened, or you will get a fake item which can fire exceptions. Note, new items don't have the EntryID property set. 

    You may find the Developing an Inspector Wrapper for Outlook 2010 article helpful.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    • Proposed as answer by Eugene Astafiev Monday, February 20, 2017 5:46 PM
    • Marked as answer by leon1526 Wednesday, February 22, 2017 11:20 AM
    Monday, February 20, 2017 4:31 PM

All replies

  • Are you only having this problem with standalone MSG files? Or with any emails, and you are essentially trying to access the original message (be it in an MSG file or in one of Outlook folders)?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, February 20, 2017 2:18 PM
  • Are you only having this problem with standalone MSG files? Or with any emails, and you are essentially trying to access the original message (be it in an MSG file or in one of Outlook folders)?

    Hi Dmitry,

    I want to find this message via its properties in the database when I reply it. If it exists, it will be marked (I put all the message information in the database). 

    As you may know, there are two kinds of original messages that reply: one is the separate .msg file, and the other is mail in the Outlook folder. For the latter, I can get its properties when selected. Does will trigger a load event when opened? Is it possible to get its properties at this time?

    I would like to know how to get these two kinds of mail properties separately in one program.
    Monday, February 20, 2017 3:15 PM
  • When you double click on an MSG file, Outlook imports it into the default message store. You never deal directly with the MSG file itself. So there is really no difference between the two cases.

    You cannot assume that the currently selected message is the one the user is replying to. What is the message was first opened for reading and displayed in an inspector? Worse that that, you can have multiple inspectors open at a time.

    What you need to do is track the Explorer.SelectionChange event and set up event handlers on the selected items. You also need to subscribe to the Application.Inspectors.NewInspector event and set up event sink on the Inspector.CurentItem object.

    You can then use MailItem.Reply/ReplyAll/Forward events to access the newly created response as well as the original message.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Proposed as answer by Eugene Astafiev Monday, February 20, 2017 5:45 PM
    • Marked as answer by leon1526 Wednesday, February 22, 2017 11:20 AM
    Monday, February 20, 2017 4:01 PM
  • Hi Leon,

    Yes, you can get the properties. When you click on the .msg file on the disk and Outlook runs a new inspector window is displayed for the .msg file. The NewInspector event of the Inspectors class is fired whenever a new inspector window is opened, either as a result of user action or through program code. Be aware, you need to wait for the first Activate event of the Inspector class to get an Outlook item opened, or you will get a fake item which can fire exceptions. Note, new items don't have the EntryID property set. 

    You may find the Developing an Inspector Wrapper for Outlook 2010 article helpful.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    • Proposed as answer by Eugene Astafiev Monday, February 20, 2017 5:46 PM
    • Marked as answer by leon1526 Wednesday, February 22, 2017 11:20 AM
    Monday, February 20, 2017 4:31 PM
  • Is there any easy way to get the properties when we double-click a .msg file or choose a mail in the Outlook folder to reply? Or would you please list detailed steps? Thank you very much for your help.

    Tuesday, February 21, 2017 2:03 AM
  • Have you seen my reply? That is the easy way.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, February 21, 2017 3:50 AM