EWS 通过SubscribeToPullNotifications订阅Exchange删除邮件

摘要

在使用拉通知的方式监听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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值