Tedderz
Tedderz

Reputation: 587

How do I determine the mailbox that contains a given item or folder with EWS?

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.

Upvotes: 2

Views: 1563

Answers (2)

douglas
douglas

Reputation: 1

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.

Upvotes: 0

grapkulec
grapkulec

Reputation: 1020

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.

Upvotes: 3

Related Questions