|
摘要
在使用拉通知的方式监听exchange邮件的时候,无法监听到收件箱删除的邮件。最后通过调试发现,在删除收件箱邮件的时候,是将收件箱的邮件移动到了deleted item文件夹,会触发Moved事件,知道删除收件箱的过程,那么就好做了。
解决办法
关于拉通知的demo可以参考上篇文章的代码
EWS 通过SubscribeToPullNotifications订阅Exchange新邮件提醒
关键代码块
this._pullsubscription = this._service.SubscribeToPullNotifications(folderIds, 30, null,
EventType.NewMail, EventType.Moved);
IEnumerable<ItemEvent> itemEvents = _pullsubscription.GetEvents().ItemEvents;
foreach (ItemEvent itemEvent in itemEvents)
{
if (itemEvent != null)
{
string uniqueId = itemEvent.ItemId == null ? string.Empty : itemEvent.ItemId.UniqueId;
if (!string.IsNullOrEmpty(uniqueId))
{
Item item = Item.Bind(this._service, new ItemId(uniqueId));
Console.WriteLine(itemEvent.EventType.ToString());
switch (itemEvent.EventType)
{
case EventType.Moved:
Console.WriteLine(item.Subject);
break;
case EventType.NewMail:
Console.WriteLine(item.Subject);
break;
default:
break;
}
}
}
}
参考资料
https://msdn.microsoft.com/zh-cn/library/office/dn458791(v=exchg.150).aspx
https://msdn.microsoft.com/en-us/library/office/dn458790(v=exchg.150).aspx
https://code.msdn.microsoft.com/exchange/exchange-2013-set-pull-14c8360b |
|
|