首页 > 解决方案 > EWS API 中的 OnEvent API 在接收收件箱中的每封电子邮件时侦听两次

问题描述

我正在创建一个新的 API,它将使用 onEvent 通知方法读取电子邮件,我会将邮件发送到另一封电子邮件。在将邮件发送到另一封邮件时,它会被发送两次。

我试图通过将 id 存储在哈希映射中并在第二次在通知方法与 id 匹配时被触发时检查 id 来过滤掉重复项,我不会发送邮件。但这不能正常工作。

我的流媒体通知:


StreamingSubscription subscription = exchangeService.subscribeToStreamingNotification(folder,EventType.NewMail);  
StreamingSubscriptionConnection conn = new StreamingSubscriptionConnection(exchangeService,30); conn.addSubscription(subscription );  
conn.addNotificationEvent(new StreamingsubscriptionConnection.INotificationEventDelegate())
    { @override 
    public void notificationEventDelegate(object sender, NotificationEventArgs args){
         StreamingSubscription subscription = args.getSubscription(); 
            for(NotificationEvent event : args.getEvents()){
                 if(event instanceof FolderEvent){
                     FolderEvent folderEvent = (FolderEvent) event; 
                 } else if (event instanceof ItemEvent){
                     ItemEvent itemEvent = (ItemEvent) event; } else{ logger.error("Unsupported event" + event.getClass)
                 }
else{
 logger.error("Unsupported event" + event.getClass) 
}

标签: javaexchangewebservices

解决方案


推荐阅读