2

I have a program that subscribes to multiple Exchange 2010 mailboxes using EWS Managed API's streaming notifications.

When I get a notification related to an item, I need to determine whose mailbox that item belongs to. I'm able to get the item's ID and the parent folder's ID, etc., but I don't see any way to determine what mailbox the item belongs to.

Tedderz
  • 587
  • 5
  • 16

2 Answers2

3

Ok, so if I understand your application correctly you are using Impersonation and create subscriptions for all impersonated users. And when you receive event from subscription you want to know for which user this event occurred. If that is the case can't you just keep your subscriptions mapped to user that subscription was created for? Simple Dictionary<StreamingSubscription, ImpersonateduserId> would be enough And when you get notification you get subscription object from NotificationEventArgs.Subscription property and find user id that subscription was created for in you map. From ImpersonatedUserId you can get smtp address (property Id) and you know which exatcly user that was.

grapkulec
  • 1,022
  • 13
  • 28
  • I was hoping for an answer that would allow me to find a mailbox just through an ItemID, but this will work. Thanks. – Tedderz Jul 11 '11 at 13:24
  • as far as I know there is no way of determining mailbox just with ItemId. for more complex configurations you can have for example several servers in cluster and if EWS service is properly configured you can access (impersonate) users from all of them while being connected only to one of them. so finding item just with ItemId probably would be too time and resource consuming or maybe even impossible to implement. – grapkulec Jul 11 '11 at 14:24
  • I ran into exactly this problem today and this is pushing me in the right direction. But can you get into a little bit more detail with your "pseudo code" example? Because to be honest I have no idea where to put that Dictionary and how I will retrieve that object. So a little bit more detail is greatly appreciated :) – Jelmer Apr 30 '14 at 14:03
  • Put that dictionary wherever it will be alive for the time of you monitoring subscriptions, member of your class, static somewhere, whatever is right in your application. And in place where you handle incoming notification events query it for impersonation id using subscription object from event you received. – grapkulec Apr 30 '14 at 14:24
0
private void OnNotificationEvent(object sender, NotificationEventArgs args)
{
 string fromEmailAddress = args.Subscription.Service.ImpersonatedUserId.Id;
}

That's how you get the Mailbox's Email Address that the item belongs to.