我正在使用EWS API从 Exchange 2007 服务器连接和检索邮件,它工作正常。现在我想收到拉通知。我在这里找到了一个示例,这是我尝试过的:
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();
但是,当我在那里放置断点时,我从来没有到达上面的开关。我已经发送了一些邮件并删除了一些,但没有任何反应。
任何想法为什么这不起作用?或者还有其他方法可以获取拉取通知吗?