adi63
adi63

Reputation: 17

VSTO Outlook ItemAdd is not fired on Outlook 365 startup for emails received while Outlook was off

I wrote a VSTO add-in for Outlook. I am in a Microsoft Exchange environment in my company. The add-in responds to new email messages with the ItemAdd event. With Outlook 2013 this worked without problems. Especially when emails were received while Outlook was not started. When Outlook started, an event was fired for each new mail item and everything was fine.

The company has now switched to Office 365. I have now noticed that Office 365 does not generate any events for newly received emails while Outlook is not running. As a workaround, I created a rule that moves emails from the default inbox to other folders. I also monitor these other folders for new emails. With this mechanism, I also recognize new emails that have arrived while Outlook was not active. I don't find this workaround particularly elegant.

The ItemAdd event doesn't seem to trigger events with Outlook 365 for mail (arrived when Outlook is not active) for me when Outlook starts. Does anyone have any idea how I can create events in Outlook 365 (other than my cumbersome workaround) for emails that came in while Outlook was off?

Upvotes: 0

Views: 58

Answers (1)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66215

Items.ItemAdd event won't fire if you are using online mode - the event only fires as Outlook synchronizes its OST cache with the server and newly created messages are downloaded and added to the folder.

Another possibility is that the folder is synchronized before your addin is loaded.

Keep in mind that all Outlook (and MAPI) events were only designed for the UI purposes - they are not guaranteed to fire and can be skipped under heavy loads.

Also note that that if too many items are added/modified/deleted at the same time, folder contents table will fire TABLE_CHANGED or TABLE_RELOAD MAPI event, which (unlike TABLE_ROW_ADDED / TABLE_ROW_DELETED / TABLE_ROW_MODIFIED events mapped to ItemAdd / ItemRemove / ItemChange in OOM correspondingly) is not exposed by Outlook at all. If using Redemption is an option (I am its author), it exposes RDOItems.CollectionModified event (raised when TABLE_CHANGED or TABLE_RELOAD are fired).

Ultimately, if you are using events for any kind of synchronization rather than UI, the events can at best serve as a hint that you need to process the folder sooner rather than later. Each time you process an item, you can store the latest item creation/modification time, then on startup, retrieve all items newer than that time stamp using Items.Restrict or Items.Find/FindNext. Keep in mind that all date/time values in OOM (but not in MAPI or Redemption) are rounded to a minute, seconds and milliseconds are always 0.

Upvotes: 0

Related Questions