I've succesfully created an EWS managed API based listener that subscribes to exchange for new email notifications on a particular mailbox. The notification handler is able to extract the recieved notification, get the ID and watermark of the affected email, retrieve the email and display the subject line. It then returns a NotificationResponse.OK to exchange to keep the SAME subscription alive.
On the next recieved notification, regardless if its actually another email or exchange checking to see if I'm there, the eventdata of the next notification contains information only of the FIRST email message. It does not reflect information for the next piece of email received. Nor does Notification.Items contain an array with the last element being the next email piece.
Do I have to cancel the subscription and resubscribe with the latest email message's watermark to continue recieving notifications for future emails after a notification was successfully processed? How do I tell exchange that I successfully processed the current notification and not to resend it anymore?
Andy
private NotificationResponse HandleNotificationReceived(object sender, SendNotificationResponseMessageType eventData) { ItemIdType modifiedItemId = null; NotificationResponse continueSubscription = NotificationResponse.OK; log("watermark=" + eventData.Notification.Items[0].Watermark); BaseObjectChangedEventType createdEvent = eventData.Notification.Items[0] as BaseObjectChangedEventType; log("eventData.Notification.Items.Count=" + eventData.Notification.Items.Count().ToString("D3")); if (createdEvent != null) { modifiedItemId = createdEvent.Item as ItemIdType; //STEP 5 GET THE ITEM OF THE NOTIFICATION AND WRITE THE SUBJECT OF THE MESSAGE log("ID=" + modifiedItemId.Id); EmailMessage email = EmailMessage.Bind(service, modifiedItemId.Id); log("subject of email: " + email.Subject); } else { nAcknowledgementCount++; log("Exchange checking if subscription is still alive..." + nAcknowledgementCount.ToString("D2")); }//EOF createdEvent != null //STEP 6 ACKNOWLEDGE SUBSCRIPTION if (nAcknowledgementCount <= 30) { continueSubscription = NotificationResponse.OK; log("Exchange subscription renewed " + nAcknowledgementCount.ToString("D2")); } else { c.StopListening(); continueSubscription = NotificationResponse.Unsubscribe; log("Exchange subscription cancelled " + nAcknowledgementCount.ToString("D2")); } return continueSubscription; }//EOF HandleNotificationReceived