I am working in 2 addins (one for Outlook 2007 and one for Outlook 2010). One of the things that these addins need to do is to add a category to the master category list (if that category is not already present).
This is how I do that:
NameSpace oNS = Application.GetNamespace("MAPI");
if (oNS.Categories[Resources.MyCategoryName] == null)
{
oNS.Categories.Add(Resources.MyCategoryName, OlCategoryColor.olCategoryColorOrange, OlCategoryShortcutKey.olCategoryShortcutKeyNone);
}
The problem is that when I have 2 or more email accounts in Outlook, the new category is added only to the first account's master category list. The master category lists of the other accounts remain unchanged. And by "first account" I mean the first account created in Outlook.
I get this behavior both in outlook 2007 and 2010.
You can access the account-specific Categories collection trough the DeliveryStore from the specific account.
var account = Application.Session.Accounts[0];
var categories = account.DeliveryStore.Categories;
If you want to search for your account you can always use linq
var account = Application.Session.Accounts.Cast<Account>()
.FirstOrDefault(a => a.ExchangeMailboxServerName == "contoso.com");