Adding delegates in Exchange Web Services (Exchange Server 2007 SP1)

Delegates & Exchange Web Services 

In Microsoft Exchange Server 2007 SP1, you can use Exchange Web Services to add, update, and remove delegates.

Code sample

Please find the code example that shows you how to add delegates that can take actions on behalf of a principal. In this code it shows how to add two delegate users to an account.

static void AddDelegate()
{
    // Set the version, credentials, and Client Access server on ExchangeServiceBinding.
    ExchangeServiceBinding esb = new ExchangeServiceBinding();
    esb.RequestServerVersionValue = new RequestServerVersion();
    esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2007_SP1;
    esb.Credentials = new NetworkCredential("username", "password", "domain");
    esb.Url = "https://example.com/ews/exchange.asmx";

    // Create the request.
    AddDelegateType request = new AddDelegateType();

    // Identify the principal's mailbox.
    request.Mailbox = new EmailAddressType();
    request.Mailbox.EmailAddress = "user1@example.com";

    // Identify the delegates who are given access to the principal's mailbox.
    request.DelegateUsers = new DelegateUserType[2];
    request.DelegateUsers[0] = new DelegateUserType();
    request.DelegateUsers[0].UserId = new UserIdType();
    request.DelegateUsers[0].UserId.PrimarySmtpAddress = "user2@example.com";
    request.DelegateUsers[1] = new DelegateUserType();
    request.DelegateUsers[1].UserId = new UserIdType();
    request.DelegateUsers[1].UserId.PrimarySmtpAddress = "user3@example.com";
   
    // Specify the permissions that are granted to each delegate.
    request.DelegateUsers[0].DelegatePermissions = new DelegatePermissionsType();
    request.DelegateUsers[0].DelegatePermissions.CalendarFolderPermissionLevel = DelegateFolderPermissionLevelType.Reviewer;
    request.DelegateUsers[0].DelegatePermissions.CalendarFolderPermissionLevelSpecified = true;
    request.DelegateUsers[1].DelegatePermissions = new DelegatePermissionsType();
    request.DelegateUsers[1].DelegatePermissions.TasksFolderPermissionLevel = DelegateFolderPermissionLevelType.Author;
    request.DelegateUsers[1].DelegatePermissions.TasksFolderPermissionLevelSpecified = true;
    request.DelegateUsers[1].DelegatePermissions.InboxFolderPermissionLevel = DelegateFolderPermissionLevelType.Editor;
    request.DelegateUsers[1].DelegatePermissions.InboxFolderPermissionLevelSpecified = true;

    // Specify whether the principal recieves meeting requests.
    request.DeliverMeetingRequests = DeliverMeetingRequestsType.DelegatesAndSendInformationToMe;
    request.DeliverMeetingRequestsSpecified = true;

    try
    {
        // Send the request and get the response.
        AddDelegateResponseMessageType response = esb.AddDelegate(request);
        DelegateUserResponseMessageType[] responseMessages = response.ResponseMessages;

        // One DelegateUserResponseMessageType exists for each attempt to add a delegate user to an account.
        foreach (DelegateUserResponseMessageType user in responseMessages)
        {
            Console.WriteLine("Results of adding user: " + user.ResponseClass.ToString());
            Console.WriteLine(user.DelegateUser.UserId.DisplayName);
            Console.WriteLine(user.DelegateUser.UserId.PrimarySmtpAddress);
            Console.WriteLine(user.DelegateUser.UserId.SID);
            if (user.DelegateUser.ReceiveCopiesOfMeetingMessagesSpecified)
            {
                Console.WriteLine("Does the delegate receive copies of meeting related messages: " + user.DelegateUser.ReceiveCopiesOfMeetingMessages);
            }
            if (user.DelegateUser.ViewPrivateItemsSpecified)
            {
                Console.WriteLine("Can the delegate view private items in the principal's mailbox: " + user.DelegateUser.ViewPrivateItems);
            }
        }
        Console.ReadLine();
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
        Console.ReadLine();
    }
}

For more information refer this article