For the case you have more accounts/stores in your Outlook and want that ItemAdd event fires e.g. for all sent items folder.
This is what I have so far but the event is not firing for all sent items folder:
foreach (Outlook.Store store in _outlookNameSpace.Stores)
{
// _SentItems = null;
// _items = null;
try
{
_SentItems = store.GetDefaultFolder(OlDefaultFolders.olFolderSentMail);
_items = _SentItems.Items;
_items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(items_ItemAdd); // BUGBUG: The problem is probably here, as the object needs to be alive which is firing the event?
}
catch
{
AppUtils.DoLog("Skipping this store.");
}
}
These guys are defined as global class variables:
Outlook.NameSpace _outlookNameSpace;
Outlook.MAPIFolder _SentItems;
Outlook.Items _items;