SliverNinja - MSFT
SliverNinja - MSFT

Reputation: 31641

Outlook Events not firing when Exchange loses connectivity

We recently noticed an issue with Outlook 2007 eventing that causes it to not trigger events when Exchange connectivity is lost and then recovered. If you attach a listener to Folder.Items.ItemAdd event, the event will get disconnected after Exchange toggles from offline to online. To reproduce this - we removed our ethernet cable in and out to simulate a brief connection loss.

This really makes it hard to build plugins if you can't guarantee events will be triggered when the Exchange connectivity has had an outage - especially common when operating from a remote office. We are not using cached exchange mode.

Does anyone have any feedback on whether their is a workaround, or how to know when we need to re-establish our event listener? Is using cached exchange mode a solution? Or are there certain events which you just can't use reliably?

There doesn't appear to be an event trigger for when Exchange connectivity is lost. Maybe the only workaround here is using some sort of timer for reliable eventing behavior.

public partial class ThisAddIn
{
  Outlook.Items sentItems;      
  private void ThisAddIn_Startup(object sender, System.EventArgs e)
  {
    Outlook.Folder sentFolder = ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
    sentItems = sentFolder.Items;
    sentItems.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(SentItems_ItemAdd);
  }
  void SentItems_ItemAdd(object Item)
  { // breakpoint never hit after Exchange connectivity is lost
    Outlook.MailItem mailItem = Item as Outlook.MailItem; 
  }
}

Upvotes: 3

Views: 931

Answers (1)

SliverNinja - MSFT
SliverNinja - MSFT

Reputation: 31641

After troubleshooting this problem, it was discovered there are certain events that are not re-established after you lose connectivity with Exchange. Events such as Application.Explorers.NewExplorer and Application.Inspectors.NewInspector are not affected by Exchange connectivity, but Folder.Items.ItemAdd is. Perhaps this is due to Folder's inheritance of MAPIFolder.Items.

The only solution to re-establishing the event triggers is to periodically reconnect the events (since we don't have an event to tell us when Exchange is unavailable) or re-attach the events during user-initiated actions such as NewInspector or MailItem.Send.

MSDN Forums recommends you don't use the ItemAdd event as only intended to be used via the UI.

Upvotes: 4

Related Questions