0
votes

I have a C# VSTO Outlook addin and I'm trying to support Outlook 2007 and up and I need to get the account names as Recipients for all Stores in the current profile. Obviously one of the Stores will be the mailbox for the current user, but there could also be delegate mailboxes opened in the current profile and I can't find a way to get the owner's of these delegate mailbox Stores using the Outlook Object Model.

Perhaps a Property Accessor?

2

2 Answers

1
votes

You can loop round the stores in your Outlook profile using the Stores property, and check the ExchangeStoreType property value of each Store to see if its the type of store you are interested in.

I haven't got a delegate mailbox in my Outlook profile, so I can't say 100% how to get the owner. But hopefully you'll be able to spot a property on the Store object that give you the information you need. e.g. the DisplayName property.

Here is an example to loop round the Stores in your Outlook profile and check what type of Exchange Store it is.

Stores stores = Application.GetNamespace("MAPI").Stores;

for (int i = 1; i <= stores.Count; i++)
{
    Store store = stores[i];

    switch (store.ExchangeStoreType)
    {
        case OlExchangeStoreType.olAdditionalExchangeMailbox:
            break;
        case OlExchangeStoreType.olExchangeMailbox:
            break;
        case OlExchangeStoreType.olExchangePublicFolder:
            break;
        case OlExchangeStoreType.olNotExchange:
            break;
        case OlExchangeStoreType.olPrimaryExchangeMailbox:
            break;
    }

    Marshal.ReleaseComObject(store);
}

Marshal.ReleaseComObject(stores);

And if you want to get the Inbox folder, you can use the GetDefaultFolder method.

MAPIFolder inboxFolder = store.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
0
votes

I have just done this using the DisplayName of the delegate account:

var app = new OutlookApp();
Stores stores = app.GetNamespace("MAPI").Stores;
MAPIFolder sentFolder = null;
foreach (Store store in stores)
{
    if (store.DisplayName == "DisplayName for your delegate account")
    {
        sentFolder = store.GetDefaultFolder(OlDefaultFolders.olFolderSentMail);
    }
}

The display name is the name of the delegate account as it is displayed in your Outlook toolbar.