This documentation is archived and is not being maintained.

Updating delegates by using the EWS Managed API 2.0

EWS Managed API

Last modified: October 13, 2012

Applies to: EWS Managed API | Exchange Server 2007 Service Pack 1 (SP1) | Exchange Server 2010

Note: This content applies to the EWS Managed API 2.0 and earlier versions. For the latest information about the EWS Managed API, see Web services in Exchange.

You can use the Microsoft Exchange Web Services (EWS) Managed API to change the permissions of delegates for another account. After you change the permissions, the delegate can only act on behalf of the account holder with the new permissions.

To update a delegate for an account

  1. Create a DelegateUser object that represents the delegate user to update.

    DelegateUser updatedDelegate = new DelegateUser("delegate@email.address");
  2. Set the permissions that you want to grant on the DelegateUser object.

    updatedDelegate.Permissions.CalendarFolderPermissionLevel = CalendarFolderPermissionLevel.Editor;
  3. Create a list of delegates to update and add the updated delegate to the list. This example uses a generic List object to hold the delegate list.

    List<DelegateUser> delegatesToUpdate = new List<DelegateUser>();
  4. Create a Mailbox object to represent the primary account for the delegates.

    Mailbox mailbox = new Mailbox("primaryAccount@email.address");
  5. Call the UpdateDelegates method to update the delegates.

    Collection<DelegateUserResponse> result = service.UpdateDelegates(mailbox, MeetingRequestDeliveryScope.DelegatesAndMe, delegatesToUpdate);

The UpdateDelegates method changes the permissions on the specified delegates to those listed in the update request. The list of delegates to update can be either an array of DelegateUser objects, or any object that implements the IEnumerable interface and returns DelegateUser objects.

This procedure assumes that a valid ExchangeService object is bound to the primary user's account, or that the primary user's account is being impersonated.

The following code example shows how to update the permission for a delegate to calendar editor and task reviewer.

    Collection<DelegateUserResponse> UpdateDelegates()
      // Bind to the service by using the primary e-mail address credentials.
      ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
      service.Credentials = new NetworkCredential(user1Name, user1Password, emailDomain);

      // Create a list to hold the updated delegates.
      List<DelegateUser> updatedDelegates = new System.Collections.Generic.List<DelegateUser>();

      // Set the new permissions for the delegate.
      DelegateUser taskDelegate = new DelegateUser(user3Email);
      taskDelegate.Permissions.CalendarFolderPermissionLevel = DelegateFolderPermissionLevel.Editor;
      taskDelegate.Permissions.TasksFolderPermissionLevel = DelegateFolderPermissionLevel.Reviewer;

      // Add the delegate to the list of updated delegates.
      // Create a mailbox object that represents the primary user.
      Mailbox mailbox = new Mailbox(user1Email);

      // Call the UpdateDelegates method to update the permissions on the specified delegates.
      Collection<DelegateUserResponse> response = service.UpdateDelegates(mailbox, MeetingRequestsDeliveryScope.DelegatesAndSendInformationToMe, updatedDelegates);

      return response;


The UpdateDelegates method in the code example returns a list of DelegateUserResponse objects, one for each delegate that is updated. Examine the DelegateUserResponse objects to determine the success or failure of the update for each delegate.

For information about compiling this code, see Getting started with the EWS Managed API 2.0.

  • Write appropriate error handling code for common search errors.

  • Review the client request XML that is sent to the Exchange server.

  • Review the server response XML that is sent from the Exchange server.

  • Set the service binding as shown in Setting the Exchange service URL by using the EWS Managed API 2.0. Do not hard code URLs because if mailboxes move, they might be serviced by a different Client Access server. If the client cannot connect to the service, retry setting the binding by using the AutodiscoverUrl(String) method.

  • Set the target Exchange Web Services schema version by setting the requestedServerVersion parameter of the ExchangeService constructor. For more information, see Versioning EWS requests by using the EWS Managed API 2.0.

  • Use HTTP with SSL for all communication between client and server.

  • Always validate the server certificate that is used for establishing the SSL connections. For more information, see Validating X509 certificates by using the EWS Managed API 2.0.

  • Do not include user names and passwords in trace files.

  • Verify that Autodiscover lookups that use HTTP GET to find an endpoint always prompt for user confirmation; otherwise, they should be blocked.