Eugene Astafiev

How to get access to hidden Outlook items via Extended MAPI?

MAPI (also known as Extended MAPI) is a powerful and complex COM-based API developed for creating mail-enabled applications. Microsoft Outlook and Exchange are among the most popular applications utilizing MAPI. Add-in Express provides Outlook developers with a free component, MAPI Store Accessor, that hides MAPI complexities to provide developers with easy access to MAPI features. One of them is hidden items.

Hidden items in Extended MAPI

Storing some application-specific data between sessions is quite a usual task for Outlook developers. Such data are store either in the Windows registry or just in a file (binary or text, custom format or XML).

The MAPI subsystem provides yet another possibility: it allows you to create and save any data in hidden items. As the name suggests, a hidden item isn’t visible in Outlook. Hidden items are similar to usual mail, contact, and task items because they have the same properties: subject, body, attachments, etc. Also, you can find the term “associated content” in various information sources which has exactly the same meanings.

As an example of this approach, Outlook saves folder view settings in hidden items. Views, custom form definitions, archive settings, and many other configuration options can be stored in such hidden items. In Outlook 2007, you can find the StorageItem class that describes a hidden item.

MAPI Store Accessor provides an easy access to this feature of MAPI through the HiddenMapiItems property of the AddinExpress.MAPI.Folder class. To demonstrate the use of this property, I developed a small application that creates a new MAPI session for the default MAPI profile and show the following form:

Create, view, and delete hidden Outlook items with a simple application.

The form allows choosing a folder name in order to see its hidden items. In the list box, I show the subject and the class name of hidden items.

You can create such an item and use standard and / or custom properties to store your data.

To set a value of some standard property in the SetProperty method, you use the corresponding property tag from the AddinExpress.MAPI.ADXMAPIPropertyTag enumeration.

To create a custom property you have to combine a property type with a property ID into the property tag. For example, consider the following code:

C#:

mapiItem.SetProperty(0x340F0003, myLongValue);

VB.NET:

mapiItem.SetProperty(CType(&H340F0003, UInteger), myLongValue)

The first parameter of the SetProperty method is a property tag. The first part of the property tag is a property ID (0x340F) and the second one is a property type. In this case the property type is PT_LONG (0x0003).

Extended MAPI allows you to choose an ID for your custom property from the predefined ranges of values. The ranges are listed in the MAPITags.h file. Here they are:

The following ranges should be used for all property IDs. Note that property IDs for objects other than messages and recipients should all fall in the range 0x3000 to 0x3FFF:

From To Kind of property
0001 0BFF MAPI_defined envelope property
0C00 0DFF MAPI_defined per-recipient property
0E00 0FFF MAPI_defined non-transmittable property
1000 2FFF MAPI_defined message content property
3000 3FFF MAPI_defined property (usually not message or recipient)
4000 57FF Transport-defined envelope property
5800 5FFF Transport-defined per-recipient property
6000 65FF User-defined non-transmittable property
6600 67FF Provider-defined internal non-transmittable property
6800 7BFF Message class-defined content property
7C00 7FFF Message class-defined non-transmittable property
8000 FFFE User-defined Name-to-id mapped property

The 3000-3FFF range is further subdivided as follows:

From To Kind of property
3000 33FF Common property such as display name, entry ID
3400 35FF Message store object
3600 36FF Folder or Adderess Book container
3700 38FF Attachment
3900 39FF Address book object
3A00 3BFF Mail user
3C00 3CFF Distribution list
3D00 3DFF Profile section
3E00 3FFF Status object

Find more about MAPI property tags on MSDN.

Available downloads:

These sample COM Add-ins were developed using Add-in Express for Office and .net:

VB.NET sample Outlook add-in
C# sample Outlook add-in

12 Comments

  • Kevin says:

    I tried to use the MAPI Store Accessor but am using Microsoft Visual C# 2010 Express, which is not provided as an option during install. Is it possible to use this component with VS Express?

  • Eugene Astafiev says:

    Hi Kevin,

    No, it is not. The Express editions of Visual Studio are not supported by the MAPI Store Accessor installer. Instead, I can send you the dll without an installer. Does it suit your needs? Which e-mail address should I use?

  • martin says:

    Hello,
    can I use mapi store accessor without using the installer.
    I want to run it in a service on a machine without visual studio installed?
    Thanks for help
    Martin

  • Eugene Astafiev says:

    Hello Martin,

    Please note that you don’t need to have Visual Studio installed on the target PC. Do you get any error messages or exceptions?

  • Kushan Randima says:

    Hi,

    After googling for quiet a lot of resources, I believe that I can’t use “MAPI Store Accessor” with Visual Studio 2013 & Add-in express v.7.7.4087. I need to set some extended properties. How I do that? Please explain.

    Thank You.

  • Andrei Smolin (Add-in Express Team) says:

    Hello Kushan,

    > I believe that I can’t use “MAPI Store Accessor” with Visual Studio 2013 & Add-in express v.7.7.4087

    Correct.

    You use the StorageItem object, see https://msdn.microsoft.com/en-us/library/office/ff864182%28v=office.15%29.aspx. To set the MAPI properties that the Outlook object model doesn’t let you modify, see the PropertyAccessor property.

  • DWE says:

    Hi – the link to the C# sample of this points to the VB example. Can you fix the link or email the example ?
    Regards
    Darrin

  • Andrei Smolin (Add-in Express Team) says:

    Hello Darrin,

    Done. You may need to press Ctrl+F5 to reload the page.

  • Nik says:

    Hi,

    Can this be used without Add-In express? I am trying to do a sample app with native Visual Studio 2019 and .NET Framework 4.7.2 (without add-in express) but I keep getting the exception Mixed mode assembly is built against version ‘v2.0.50727’ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

    Can you please provide a .NET 4.7.2 compatible version of this tool?

  • Andrei Smolin (Add-in Express Team) says:

    Hello Nik,

    We won’t be able to provide such a version because this tool is not supported any longer.

    As to hidden items, the Outlook object model allows creating such items using the Outlook.MAPIFolder.GetStorage() method that is available in Outlook 2007 and higher. See also https://docs.microsoft.com/en-us/office/vba/api/outlook.folder.getstorage.

  • Justin says:

    Hello,

    I’ve inherited an older project that utilizes AddinExpress that needs to be updated to .NET 4.5.2. I just upgraded to the latest version of AddinExpress. But the project also uses AddinExpress.MAPI. I’m receiving the following exception at runtime: “Mixed mode assembly is built against version ‘v2.0.50727’ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.”
    What would be the workaround for this?

    Thanks!
    Justin

  • Andrei Smolin (Add-in Express Team) says:

    Hello Justin,

    AddinExpress.MAPI doesn’t support .NET 4.X. You need to replace AddinExpress.MAPI calls with equivalent calls of PropertyAccessor object. You get such an object using the PropertyAccessor property available on all Outlook item types (e.g. MailItem) as well as on some non-item classes. See https://docs.microsoft.com/en-us/office/vba/api/outlook.propertyaccessor.

Post a comment

Have any questions? Ask us right now!