I am using the EWS API to connect and retrieve mail from a exchange 2007 server, which works fine. Now I would like to get pull notifications. I have found a example here, which is what I have tried:
public IEnumerable<ItemEvent> GetPullNotifications(FolderId folderId)
{
PullSubscription subscription = Service.SubscribeToPullNotifications(new FolderId[] { folderId }, 5, null, EventType.NewMail, EventType.Created, EventType.Deleted);
return subscription.GetEvents().ItemEvents;
}
public void CheckPullNotifications(object source, ElapsedEventArgs e)
{
Console.WriteLine("Check...");
IEnumerable<ItemEvent> itemEvents = ewsClient.GetPullNotifications(WellKnownFolderName.Inbox);
foreach (ItemEvent itemEvent in itemEvents)
{
switch (itemEvent.EventType)
{
case EventType.NewMail:
MessageBox.Show("New mail: " + itemEvent.ItemId.UniqueId);
break;
case EventType.Deleted:
MessageBox.Show("Mail deleted: " + itemEvent.ItemId.UniqueId);
break;
}
}
return;
}
//...
Timer myTimer = new Timer();
myTimer.Elapsed += new ElapsedEventHandler(CheckPullNotifications);
myTimer.Interval = 1000;
myTimer.Start();
However, I never get to the above switch when I put a breakpoint there. I've send a few mails and deleted some, nothing happens.
Any ideas why this does not work? Or are there any other ways to get pull notifications?