none
PropertyAccessor.GetProperty always returns exception RRS feed

  • Question

  • Hello there, I need to save permanently some custom information inside an Outlook Mailitem and retrieve them back.

    My case scenario is the following: I select an email in Outlook 2013 explorer, write inside that email some information/properties, save it on my disk as .msg file, delete the email from the Inbox Outlook folder, open the .msg file as Outlook.MailItem and read that information in order to keep them or change them.

    To write properties in the Mailitem I'm using the PropertyAccessor.SetProperty() method and in order to retrieve them back the PropertyAccessor.GetProperty() one. The set action works fine, by using OutlookSpy I can see the property sored inthe .msg but when I try to get it then an exception occurs ("System.Runtime.InteropServices.COMException <0x8004010F>: Property ... unknown or not found").

    Code example:

    // to set... 'mail' type is Outlook.MailItem

    mail.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/Prop01", "value01");

    mail.Save();

    // to get

    dynamic v1 = mail.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/Prop01"); // here the exception occurs
    string V1 = (string)v1;
    Console.WriteLine("Custom value is " + V1);

    Where am I wrong? Thank you

    Monday, November 17, 2014 9:33 AM

Answers

  • Hello,

    User properties are not persisted when you open a MSG file in Outlook. Instead, you may use a low-level API to open .msg files directly. For example, Redemption can be used for that. See Outlook OpenSharedItem lose User properties for more information. 

    But I'd suggest using hidden items or folders in Outlook for storing any custom information. For example, you may save a copy of your message in a hidden folder (mark it as hidden using the PR_ATTR_HIDDEN flag). In that case you will be able to read all the properties you need.  Or you may use a StorageItem for saving any information separately.

    • Marked as answer by baru13 Monday, November 17, 2014 2:05 PM
    Monday, November 17, 2014 10:21 AM

All replies

  • Hello,

    User properties are not persisted when you open a MSG file in Outlook. Instead, you may use a low-level API to open .msg files directly. For example, Redemption can be used for that. See Outlook OpenSharedItem lose User properties for more information. 

    But I'd suggest using hidden items or folders in Outlook for storing any custom information. For example, you may save a copy of your message in a hidden folder (mark it as hidden using the PR_ATTR_HIDDEN flag). In that case you will be able to read all the properties you need.  Or you may use a StorageItem for saving any information separately.

    • Marked as answer by baru13 Monday, November 17, 2014 2:05 PM
    Monday, November 17, 2014 10:21 AM
  • Damn! In my case I can not use extra folder or item... I think I will use a default  "not too much used" string MailItem property such as "ReminderSoundFile" to store my custom information inside the MailItem. I will separate each one information by the ';' character and I will get a specific custom property by parsing the "ReminderSoundFile" property.

    Thanks for your hint!

    Monday, November 17, 2014 11:34 AM
  • You may also consider using the PR_COMMENT property for that. The PropertyAccessor class will help you with setting or getting values.
    Monday, November 17, 2014 12:09 PM
  • It seems interesting... but I don't understand how to set/get this string field. Is PR_COMMENT a MailItem field? Can you provide a setting and getting exemple?

    • Edited by baru13 Monday, November 17, 2014 1:36 PM
    Monday, November 17, 2014 1:36 PM
  • The DASL value for the PR_COMMENT property is "http://schemas.microsoft.com/mapi/proptag/0x3004001F" . You can use any low-level property (Extended MAPI) viewer, such as MFCMAPI or Outlook Spy, for exploring properties.
    Monday, November 17, 2014 2:01 PM
  • Perfect, I will try with this one. Thanks and have a nice day.
    Monday, November 17, 2014 2:05 PM