locked
How to: subscribe to many Exchange mailboxes, all on different Exchange servers? RRS feed

  • Question

  • I am building a solution that subscribes to a few thousands Exchange mailboxes all on different Exchange servers, different domains. I have to get new emails from these mailboxes, import them in our LOB and then delete emails from the original mailbox.

    The idea is to build the solution using EWS Managed API's and to make it either work as a scheduled job or as a windows service.

    Should l use streaming notification for this solution?  
    I have a doubt because I have to handle many mailboxes but because all of them are on different Exchange servers I think that I have to create as many instances of exchange service and streaming connections as the number of subscriptions is. Right?

    Another question is, if I have windows service and I use streaming notifications how can I add new mailbox other than stop and re-start the service?

    I will appreciate very much if someone can answer my question.
    • Edited by SanjaDj Tuesday, September 4, 2012 7:51 AM To ask for a help again
    Friday, August 31, 2012 8:13 AM

Answers

  • Hello SanjaDj,

    Assuming all target mailboxes are on Exchange 2010+ or Exchange Online, streaming notifications + synchronization should be used to get the new mail messages. Depending on the target servers, you will need to bundle subscriptions based on server endpoint (Autodiscover results) and throttling settings. Exchange Online settings are the most restrictive. By default, your customers installed Exchange Servers will have larger EWSMaxSubscription settings.

    So, to answer your question, " I think that I have to create as many instances of exchange service and streaming connections as the number of subscriptions is. Right?", use one ExchangeService object per calling service account --the EWS Managed API is not thread-safe. Since you can get notifications from many subscriptions, you should bundle subscriptions for mailboxes that use the same service endpoint up to the maximum number of subscriptions as determined by the EWSMaxSubscriptions throttling limit and also the EWSMaxConcurrency limit. 

    For example, assume:
    - you have customer A with 8000 Exchange Online mailboxes. All of these mailboxes are serviced through a single Autodiscover endpoint. One subscription per mailbox.
    - you have customer B with 2000 Exchange 2010 SP2 mailboxes. 500 mailboxes use endpoint I, 600 use endpoint II, 900 use endpoint III. One subscription per mailbox.

    For customer A, you may need to use two or more service accounts. If we assume 2 service accounts, each service account will manage 4000 subscriptions, one for each mailbox. You will have 2 ExchangeService objects, one per service account. Assuming that each service account is limited to 20 open connections (EWSMaxConcurrency limit), each service connection should handle at most 200 (4000 subscriptions/20 cnxs) subscriptions per connection. Essentially, when you call GetStreamingEvents (1 connection), you will pass in 200 subscription identifiers. Again, the assumption is that all mailboxes that contain the target subscription are serviced by the same endpoint.

    For customer B, you will want to bundle 200 subscriptions in a connection just like you did for customer A. All 200 subscriptions should target the same endpoint. So, for endpoint I, you will have three connections (200 subscriptions, 200 subscriptions, 100 subscriptions). For endpoint II, you will have three connections (200, 200, 200). For endpoint III, you will have five connections (200, 200, 200, 200, 100). 

    To answer your question about adding subscriptions to your window service application, I'm not sure if I understand your question. Your windows service application just needs an input to identify which mailbox to subscribe to (Subscribe operation) and then add the new subscription identifier to the next GetStreamingEvents request. The Subscribe operation requires impersonation.

    I hope this helps.


    Michael | Microsoft Exchange SDK

    The Exchange Development Forum Guide has useful information for using the Exchange Development Forum.

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.


    Tuesday, September 4, 2012 11:10 PM

All replies

  • Anyone? I would really appreciate if someone can answer my questions or point me to the right documentation.

    Using Streaming Notifications for multiple users is not documented at all, or maybe I can’t find the documentation.

    Some suggest in forum questions that it is necessary to use an instance of ExchangeService regardless if users are on the same Exchange server or not, with or without impersonation.

    Tuesday, September 4, 2012 8:41 AM
  • Hello SanjaDj,

    Assuming all target mailboxes are on Exchange 2010+ or Exchange Online, streaming notifications + synchronization should be used to get the new mail messages. Depending on the target servers, you will need to bundle subscriptions based on server endpoint (Autodiscover results) and throttling settings. Exchange Online settings are the most restrictive. By default, your customers installed Exchange Servers will have larger EWSMaxSubscription settings.

    So, to answer your question, " I think that I have to create as many instances of exchange service and streaming connections as the number of subscriptions is. Right?", use one ExchangeService object per calling service account --the EWS Managed API is not thread-safe. Since you can get notifications from many subscriptions, you should bundle subscriptions for mailboxes that use the same service endpoint up to the maximum number of subscriptions as determined by the EWSMaxSubscriptions throttling limit and also the EWSMaxConcurrency limit. 

    For example, assume:
    - you have customer A with 8000 Exchange Online mailboxes. All of these mailboxes are serviced through a single Autodiscover endpoint. One subscription per mailbox.
    - you have customer B with 2000 Exchange 2010 SP2 mailboxes. 500 mailboxes use endpoint I, 600 use endpoint II, 900 use endpoint III. One subscription per mailbox.

    For customer A, you may need to use two or more service accounts. If we assume 2 service accounts, each service account will manage 4000 subscriptions, one for each mailbox. You will have 2 ExchangeService objects, one per service account. Assuming that each service account is limited to 20 open connections (EWSMaxConcurrency limit), each service connection should handle at most 200 (4000 subscriptions/20 cnxs) subscriptions per connection. Essentially, when you call GetStreamingEvents (1 connection), you will pass in 200 subscription identifiers. Again, the assumption is that all mailboxes that contain the target subscription are serviced by the same endpoint.

    For customer B, you will want to bundle 200 subscriptions in a connection just like you did for customer A. All 200 subscriptions should target the same endpoint. So, for endpoint I, you will have three connections (200 subscriptions, 200 subscriptions, 100 subscriptions). For endpoint II, you will have three connections (200, 200, 200). For endpoint III, you will have five connections (200, 200, 200, 200, 100). 

    To answer your question about adding subscriptions to your window service application, I'm not sure if I understand your question. Your windows service application just needs an input to identify which mailbox to subscribe to (Subscribe operation) and then add the new subscription identifier to the next GetStreamingEvents request. The Subscribe operation requires impersonation.

    I hope this helps.


    Michael | Microsoft Exchange SDK

    The Exchange Development Forum Guide has useful information for using the Exchange Development Forum.

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.


    Tuesday, September 4, 2012 11:10 PM
  • Hi Michael,

    Thanks a lot for your reply, this helps a lot!

    In my window service application I won’t use service account, impersonation, as I am monitoring one user mailbox per company.
    Do you see any issue with this? I am referring here to your comment “The Subscribe operation requires impersonation”.

    My question about adding new subscriptions was about adding new user/company subscription to the running window service but I think I have figured that out.
    Please note that I am using EWS Managed API and not EWS, I never make a direct call to GetStreamingEvents operation.

    Kind regards,
    Sanja

    Wednesday, September 5, 2012 10:37 AM
  • Hello Sanja,

    So essentially, your application requires the credentials for each monitored mailbox. If that is the case, then you don't need impersonation, in fact you wouldn't be able to use impersonation. You will have one ExchangeService object per mailbox/company. Your process will be managing many ExchangeService objects. Regarding my comment, I was assuming that a service account was accessing many mailboxes in one organization. If the credentials are being passed for the target mailbox, then impersonation is not necessary.

    With regards,


    Michael | Microsoft Exchange SDK

    The Exchange Development Forum Guide has useful information for using the Exchange Development Forum.

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Wednesday, September 5, 2012 5:42 PM
  • Great! Thanks again.

    Regards,
    Sanja

    Wednesday, September 5, 2012 5:58 PM