Adding a property on Aspose.Email and reading it on Interop.Outlook.MailItem

0

I have an App that uses Aspose.Email on the server side and Microsoft.Office.Interop.Outlook on the client side.

I want to add some named values to my MailMessage (or MapiMessage) so that they can be read in Microsoft.Office.Interop.Outlook.MailItem.ItemProperties. Can anyone help me with this?

I’ve tried several things, but the last server side version is:

MapiMessage mapiMessage = MapiMessage.FromStream(memStream);

long ltag = mapimessage.NamedPropertyMapping.GetNextAvailablePropertyId(MapiPropertyType.PT_UNICODE);
MapiProperty stringProp = new MapiProperty(ltag, Encoding.Unicode.GetBytes("testPropValue"));

mapimessage.AddCustomProperty(stringProp , "testProp");

And on the client side I want to read the values like this:

Outlook.MailItem mi = (Outlook.MailItem)Item;
string test = mi.ItemProperties["testProp"];

EDIT (OutlookSpy):

When I use OutlookSpy, the only reference to "testProp" appears in the property with tag "0x80CB UserProperties" of type "PT_BINARY" and on the Symbol field:

Version: 0x0103
FieldDefinitionCount : 1 (0x00000001)
FieldDefinitions[0]
  Flags: 0x0000002D = PDO_IS_CUSTOM | PDO_PRINT_SAVEAS | PDO_CALC_AUTO | PDO_FT_SWITCH
  VT: 0x0008 = VT_BSTR
  DispId : 0 (0x00000000)
  NmidNameLength : 8 (0x0008)
  NmidName: testProp
  NameANSI:
    PackedAnsiString.Length: 8 (0x08)
    PackedAnsiString.Characters: testProp
  FormulaANSI:
    PackedAnsiString.Length: 0 (0x00)
    PackedAnsiString.Characters: 
  ValidationRuleANSI:
    PackedAnsiString.Length: 0 (0x00)
    PackedAnsiString.Characters: 
  ValidationTextANSI:
    PackedAnsiString.Length: 0 (0x00)
    PackedAnsiString.Characters: 
  ErrorANSI:
    PackedAnsiString.Length: 0 (0x00)
    PackedAnsiString.Characters: 
  InternalType: 0x00000000 = iTypeFormula
  SkipBlocks[0]
    Size: 17 (0x00000011)
    Contents:
      PackedUnicodeString.Length: 8 (0x08)
      PackedUnicodeString.Characters: testProp
  SkipBlocks[1]
    Size: 0 (0x00000000)
c#
outlook
aspose
asked on Stack Overflow Feb 16, 2018 by Ivozor • edited Feb 19, 2018 by Ivozor

1 Answer

0

If a property is set on an item on the MAPI level (where all the properties are stored in Outlook), it can be accessed using MailItem.PropertyAccessor.GetProperty. To figure out the DASL property name (to be used in GetProperty) and to check if the property is really there, take a look at the message with OutlookSpy (click IMessage button).


User contributions licensed under CC BY-SA 3.0