Reputation: 478
I am currently using EWS Managed API to subscribe users to Pull Notification on Exchange 2010 server to get notification on Calendar items, and it is working fine. How I did this is I retrieved a list of users with their email from a SQL database and then loop through each of them and subcribe each of them to Pull Notification using SubscribeToPullNotifications()
and then GetEvents()
. I subscribe to events Created
, Modified
and Deleted
on folder Calendar.
I am thinking will that be other better way to get all the notifications from Exchange server besides looping every users one by one, because at any given time, not all users have notifications, only user where if they create, update or delete items in their calendar in MS Outlook will have event fired from Exchange server.
For example, there are 200 users retrieved from SQL database, but only 10 of them are creating new appointment in MS Outlook, but because I am looping each of them, I need to have 200 looping to get the 10 notifications from that 10 users.
Is there a way to get all notifications from the Exchange server at once at any give time so that there is no need to loop through all users to see whether there is any event from the Exchange server? I know maybe it might be better to use Push or Streaming Notification, but I would like to know is there any better way to do this using Pull Notification?
Thanks.
Upvotes: 4
Views: 3834
Reputation: 31651
An EWS subscription is tied to a single mailbox - you can't subscribe across multiple stores yet (tested on Exchange 2010).
You can subscribe to multiple folders within a mailbox using SubscribeToPullNotifications()
passing in the IEnumerable<FolderId>
for all the mailbox folders (Inbox, Sent Items, etc.) you want to subscribe to.
You would need to use a delegate account that has access to all users mailboxes - which it sounds like you already have.
FolderId folder1 = new FolderId(WellKnownFolderName.Calendar, new Mailbox("[email protected]"));
FolderId folder2 = new FolderId(WellKnownFolderName.Calendar, new Mailbox("[email protected]"));
var folderIds1 = new FolderId[] { folder1 };
var folderIds2 = new FolderId[] { folder2 };
var trackedEvents = new EventType[] { EventType.Deleted, EventType.Created, EventType.Modified }
PullSubscription subscription1 = service.SubscribeToPullNotifications(folderIds1,10,null,trackedEvents);
PullSubscription subscription2 = service.SubscribeToPullNotifications(folderIds2,10,null,trackedEvents);
// call subscrition.GetEvents() to retrieve new entries
GetEventsResults subEvents1 = subscription1.GetEvents();
GetEventsResults subEvents2 = subscription2.GetEvents();
Upvotes: 5