0

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;

1 Answer 1

1

Create a wrapper class that takes Items object as a parameter in its constructor, saves it in a field, and sets up an ItemAdd event handler. You can then initialize a wrapper for each store and store then in a list to ensure the wrappers (and their Items objects) stay alive and can raise events.

Sign up to request clarification or add additional context in comments.

2 Comments

As always thank you very much Dmitry. Any code sample which could help me?
I don't have a ready to use sample, but it is trivial to implement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.