Search code examples
c#outlookoffice-interopoffice365

How to read Custom Attributes from Exchange mailbox in Outlook Add-in


User uses Outlook 2013 and has account in Office365. I want to create similar window like Address Book in Outlook. So I have created new Outlook 2013 Add-in to display list of users. The code looks like this:

var list = Globals.ThisAddIn.Application.Session.GetGlobalAddressList();
var users = list.AddressEntries.Cast<AddressEntry>()
                .Where(ae => ae.AddressEntryUserType == OlAddressEntryUserType.olExchangeUserAddressEntry).ToList());

And it works. But In exchange, mailboxes have Custom Attributes and some of theme are set. I want to display this attributes on my list but I don't know how to retrieve them.

In Powershell you can do this:

Get-Mailbox -Identity alexB | FL

and you can see that this object has properties like "CustomAttribute1", "CustomAttribute2", ... How to do the same in outlook add-in.


Solution

  • After many OutlookSpy craches I found this :) To get custom attribute number 6 you must call:

    var prope = user.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x8032001E");
    

    Attribute:

    • #7 = 0x8033001E
    • #8 = 0x8034001E
    • ...