Retrieving custom property value from received mail using GetProperty (which was set using SetProperty in Outlook VBA)

StackOverflow https://stackoverflow.com/questions/16839870

  •  30-05-2022
  •  | 
  •  

Question

Reference: Outlook 2013 Windows 8

I have set a custom property on an outgoing mail using SetProperty. I am able to see this property and its value in the internet message header once the mail is received on another machine. I am not able to retrieve the value of this property using GetProperty even though, the property and its associated value exist in the received mail.

Property is set using the code below :

Const SchemaPrefix As String = "http://schemas.microsoft.com/mapi/string/"
Const SchemaCode As String = "{00020386-0000-0000-C000-000000000046}/ABC-ID"

Dim pa As Outlook.PropertyAccessor

Dim ID_Schema As String
Dim ID_Value As String

ID_Schema = SchemaPrefix & SchemaCode
ID_Value = "12345"

Set pa = item.PropertyAccessor
pa.SetProperty ID_Schema, ID_Value

In the mail received on another machine, I am able to see that the internet messager header contains :

ABC-ID: 12345

However, the following code fails, and returns the error - The property "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/ABC-ID" is unknown or cannot be found.
Error occurs on the last line : pa.GetProperty(ID_Schema)

Const SchemaPrefix As String = "http://schemas.microsoft.com/mapi/string/"
Const SchemaCode As String = "{00020386-0000-0000-C000-000000000046}/ABC-ID"

Dim pa As Outlook.PropertyAccessor
Dim ID_Schema As String
Dim objFolder As Folder

ID_Schema = SchemaPrefix & SchemaCode

Set objFolder = Outlook.ActiveExplorer.CurrentFolder
Set pa = objFolder.Items.item(1).PropertyAccessor
MsgBox pa.GetProperty(ID_Schema)

In the test folder, there is only one email... and I am able to manually verify the existence of the custom property and its value as set on the sending machine

Have found a few references on the web on how to set the property... but none on how to retrieve the property value. Guidance would be much appreciated.

Was it helpful?

Solution

The custom MIME property will not be automatically promoted to a named MAPI property from a MIME header. Exchange used to that, but not anymore - since you can have at most 0xFFFF unique named properties, this is a nice denial of service channel: just send a message with a few thousand x-headers to a mailbox, and you will permanently toast it.

If you see the custom x-header in PR_TRANPORT_MESSAGE_HEADERS (use OutlookSpy - I am its author - and look at the message to see that and all other MAPI properties - click IMessage button), you can read the MIME headers and programmatically extract your custom header. PR_TRANPORT_MESSAGE_HEADERS can be accessed using MailItem.PropertyAccessor, its DASL name is http://schemas.microsoft.com/mapi/proptag/0x007D001F.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top