Multiple mailboxes

Apr 3, 2009 at 9:42 AM
How do I maintain these notifications for multiple users?

Do I have to create multiple adapters ans thus creating multiple subscription collections?
How to read them and check the individual subscriptions for these multiple mailboxes?

Thanks in advance,
Ben Hiep
Apr 5, 2009 at 10:04 PM
It depends on the type of adapter you are using. The built-in adapter is a very simply one that does not support auto discover. Thus, it always points to a single server. So you group your users by server and create one adapter and one SubscriptionCollection for each group.

Apr 6, 2009 at 9:04 AM
Thanks for your reply.

I will deepen the question I am facing. I need the ability to do the trick, like in the component but then for multiple 'individual' users. So it can not be based on a group. If a notification comes in it has to be monitored on an individual user's basis. So my question was:

Do I have to instantiate multiple variables or an arraycollection of the ExchangeWebServices class? Or is there another trick in the book. This adapter has only one! NetworkCredential that can be serviced. This is done by the method CreateWcfChannelFactory. Is it possible to change this to multiple or should I leave it as it is?

Best Regards,
Apr 6, 2009 at 5:36 PM

the "group" I was referring to was more a metaphorical one.

Bottom line: If you are using the built-in adapter, you need one SubscriptionCollection for each server you are accessing. Multiple users can be added to one collection as long as they are on one server.

I'm currently working on a sample application that contains an adapter that supports AutoDiscover. That element can support multiple servers and will eleminate the need to create multiple collections.

Kind regards,
Henning Krause
Apr 8, 2009 at 12:11 PM

Thanks for all the information.
I wonder if it is also possible to just facilitate the push notification in a way that I do not know the credentials of a specific person. So the service can be activated for specific mailboxes just by an administrator. Or is writing a user interface for the user of that box the best option where he/she verifies the credentials and from that point the notification service is started. Or is it possible to use an event sink when for instance the credentail object can be captured after the logon of this specific user via OWA for instance.

I know this is a though cookie to bake, but I was asked to write such a  forward service from the company mailbox to ones private box.

Thanks in advance,
Apr 8, 2009 at 12:15 PM

you can either use delegate access or impersonation to access the mailboxes of other users.

See and

Kind regards,
Apr 8, 2009 at 12:58 PM

Dear Henning,

As I understand it correctly I could do the trick like this:

var adapter = new ExchangeWebServicesAdapter(new Uri("https://xxxxxx/ews/exchange.asmx"),

                                                             new NetworkCredential("service", "svcpass", "domain"));

                adapter.ImpersonationSettings.PrimarySmtpAddress = "";

                adapter.ImpersonationSettings.PrincipalName = " johndoe1";

When a new email comes in for johndoe1 it is  handled via the:

subscription.NewMail += (sender, e) eventhandler for this "” using the networkcredential of service or do I have to turn it around?

Kind Regards,


From: hkrause []
Sent: woensdag 8 april 2009 13:16
To: Hiep, B.
Subject: Re: Multiple mailboxes [exchangenotification:52154]

From: hkrause


you can either use delegate access or impersonation to access the mailboxes of other users.

See and

Kind regards,

Read the full discussion online.

To add a post to this discussion, reply to this email (

To start a new discussion for this project, email

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at

Apr 13, 2009 at 10:55 AM

yes, you are right. You can access the mailbox of another user with your credentials once you have the impersonation permission set. But you only need to set one of the identifier - either primary smtp address, principal odr sid.

Kind regards,
Henning Krause
Apr 16, 2009 at 7:54 AM
Edited Apr 16, 2009 at 7:58 AM
Hi Henning,

Sample impersonation above is tied up to specific user, my question is what if I need to impersonate all accounts? Is this possible? How?

Do I have to identify all users PrimarySMTPAddress and add them to collection?

Apr 16, 2009 at 8:19 AM
Hi Gesyley,

once you have a  user that has impersonation rights, you can open any mailbox by specifying the primary email address of the user in a FindItem or GetItem request.

Kind regards,
Apr 16, 2009 at 9:38 AM

Dear Henning,

The example you gave worked. Like above stated I want to extend to multiple users who are services by the service account.
So do I have two create a List of adapters for more than one user. And how do I handle the subscriptioncollection for multiple adapters and thus the subscription.newmail event?




List<ExchangeWebServicesAdapter> adpList =



new List<ExchangeWebServicesAdapter>();



Uri uriCas = new Uri("https://xxxxxx/ews/exchange.asmx");



NetworkCredential credService = new NetworkCredential("service", "svcpass", "domain");



foreach (var user in usercollection)




    adp = new ExchangeWebServicesAdapter(uriCas, credService);


    adp.ImpersonationSettings.PrincipalName = user.PrincipalName;





Can I still use one listener and handle all the different adapters or do I have to play it another way?
In this case I will likely have multiple subscriptioncollections or is there also another way?
This because I still want to use one event handler for this of course:


subscription.NewMail += (sender, e) => MyEventFollowUp(....);

Best Regards,



Apr 16, 2009 at 11:20 AM

did you use active directory services in getting users email?

Apr 16, 2009 at 12:49 PM

I did get users principal name.
I just want to patch through to their personal email address, which I can take from the Active Directory Custom Attribute. Just telling them I have a message in your professional box and flag that in their personal mailbox.

Best Regards,
Apr 21, 2009 at 6:22 AM
Based on the ItemId returned by the event, How can I determine which user mailbox this ItemId belongs to?
Apr 21, 2009 at 6:46 AM

you can't determine it from the ItemId, as the mailbox identifier is coded into the binary part of the ItemId. However, the Subscription the event comes from has a reference to the original folder it's registered on. So you can cast the sender property of an event to a Subscription instance. Then, get the Mailbox property of the first item in the Folders collection of that subscription. That object contains the email address of the mailbox this subscription is bound to.

Apr 21, 2009 at 9:19 AM
Edited Apr 22, 2009 at 3:31 AM
Thanks, it works.
Apr 22, 2009 at 3:33 AM
Edited Apr 22, 2009 at 8:31 AM
I made it to work...

using (var listener = new PushNotificationListener())

                    foreach (var adapter in adpList)
                        var subscriptionCollection = new SubscriptionCollection(adapter);
                        var emailAddress = adapter.ImpersonationSettings.PrimarySmtpAddress;
                             new[] {new FolderReference(WellKnownFolderId.Calendar,new MailboxReference(emailAddress))},

                         foreach (var subscription in subscriptionCollection)
                             Console.Out.WriteLine("Creating subscription for: {0}", ((MailboxReference)subscription.Folders[0].Mailbox).Address);
                             subscription.ItemCreated += (sender, e) =>
                                SendMessage("New",((ItemReference)e.ItemId).Id, ((MailboxReference)((Subscription)sender).Folders[0].Mailbox).Address);
                             subscription.ItemModified += (sender, e) =>
                                SendMessage("Modified",((ItemReference)e.ItemId).Id, ((MailboxReference)((Subscription)sender).Folders[0].Mailbox).Address);
                             subscription.ItemMoved += (sender, e) =>
                                SendMessage("Moved",((ItemReference)e.ItemId).Id, ((MailboxReference)((Subscription)sender).Folders[0].Mailbox).Address);
                             subscription.ItemDeleted += (sender, e) =>
                                SendMessage("Deleted",((ItemReference)e.ItemId).Id, ((MailboxReference)((Subscription)sender).Folders[0].Mailbox).Address);

                    Console.Out.WriteLine("Waiting for notifications... Hit [Enter] to quit...");