Agregar y quitar delegados mediante EWS en ExchangeAdd and remove delegates by using EWS in Exchange

Obtenga información sobre cómo agregar o quitar delegados de los buzones de los usuarios mediante la API administrada de EWS o EWS en Exchange.Learn how to add delegates to or remove delegates from users' mailboxes by using the EWS Managed API or EWS in Exchange.

Puede usar la API administrada de EWS o EWS para permitir que los delegados actúen en nombre de un propietario de buzón o quitar el acceso de un delegado a un buzón.You can use the EWS Managed API or EWS to enable delegates to act on behalf of a mailbox owner or remove a delegate's access to a mailbox. Los usuarios que se agregan como delegado y reciben permisos pueden realizar tareas en nombre del propietario del buzón.Users who are added as a delegate, and are given permissions, can perform tasks on behalf of the mailbox owner. Por ejemplo, pueden crear y enviar invitaciones a reuniones, enviar mensajes de correo electrónico y responder a convocatorias de reunión en nombre del propietario del buzón.For example, they can create and send meeting invitations, send emails, and respond to meeting requests on the mailbox owner's behalf.

Tabla 1. Métodos de la API administrada de EWS y operaciones EWS para agregar y quitar delegadosTable 1. EWS Managed API methods and EWS operations for adding and removing delegates

TareaTask Método de la API administrada de EWSEWS Managed API method Operación de EWSEWS operation
Agregar delegadosAdd delegates
ExchangeService. AddDelegatesExchangeService.AddDelegates
AddDelegateAddDelegate
Quitar delegadosRemove delegates
ExchangeService. RemoveDelegatesExchangeService.RemoveDelegates
RemoveDelegateRemoveDelegate

Una vez que se conceden permisos a una carpeta a un delegado, éstos pueden actuar sobre los elementos de la carpeta y las subcarpetas, de acuerdo con sus permisos delegados.After a delegate is granted permissions to a folder, they can act on items in the folder and any subfolders, according to their delegate permissions. Los permisos para delegados solo se aplican a las subcarpetas que se crean después de conceder el acceso de delegado.Permissions for delegates only apply to subfolders that are created after the delegate access was granted. Para actualizar los permisos de carpeta de las carpetas preexistentes, o de otras carpetas, consulte set Folder permissions for a otro usuario Using EWS in Exchange.To update folder permissions for pre-existing folders, or other folders, see Set folder permissions for another user by using EWS in Exchange.

Tenga en cuenta que los delegados solo se pueden agregar a las cuentas habilitadas para buzón, incluidos los grupos de seguridad habilitados para correo.Note that delegates can only be added to mailbox-enabled accounts, including mail-enabled security groups. De forma predeterminada, una sola llamada de acceso de delegado EWS puede tener acceso a un máximo de 255 buzones diferentes.By default, a single EWS delegate access call can access a maximum of 255 different mailboxes.

Agregar delegados mediante la API administrada de EWSAdd delegates by using the EWS Managed API

Puede Agregar delegados a un buzón mediante el método de la API administrada de EWS de AddDelegates .You can add delegates to a mailbox by using the AddDelegates EWS Managed API method. En este ejemplo, se crea un nuevo objeto de DelegateUser de correo, contacto y calendario, y a cada delegado se le proporcionan permisos de editor para su carpeta respectiva.In this example, a new calendar, contact, and email DelegateUser object is created, and each delegate is given Editor permissions for their respective folder. Puede modificar el ejemplo para agregar un delegado a cualquiera de las carpetas especificadas por las propiedades DelegatePermissionsy puede establecer los permisos para cualquiera de los valores especificados por la enumeración DelegateFolderPermissionLevel .You can modify the example to add a delegate to any of the folders specified by the DelegatePermissions properties, and you can set the permissions to any of the values specified by the DelegateFolderPermissionLevel enumeration.

En este ejemplo se supone que el servicio es un objeto ExchangeService válido para el propietario del buzón y que el usuario se ha autenticado en un servidor de Exchange.This example assumes that service is a valid ExchangeService object for the mailbox owner, and that the user has been authenticated to an Exchange server.

public static Collection<DelegateUserResponse> AddDelegates(ExchangeService service)
{
    // Create a list to hold the new delegates to add.
    List<DelegateUser> newDelegates = new System.Collections.Generic.List<DelegateUser>();
    // Create a new delegate that has editor access to the mailbox owner's Calendar folder.
    DelegateUser calendarDelegate = new DelegateUser("calendardelegate@contoso.com");
    calendarDelegate.Permissions.CalendarFolderPermissionLevel = DelegateFolderPermissionLevel.Editor;
    // Add the delegate to the list of new delegates.
    newDelegates.Add(calendarDelegate);
    // Create a new delegate that has editor access to the mailbox owner's Contacts folder.
    DelegateUser contactDelegate = new DelegateUser("contactdelegate@contoso.com");
    contactDelegate.Permissions.ContactsFolderPermissionLevel = DelegateFolderPermissionLevel.Editor;
    // Add the delegate to the list of new delegates.
    newDelegates.Add(contactDelegate);
            
    // Create a new delegate that has editor access to the mailbox owner's Inbox folder.
    DelegateUser emailDelegate = new DelegateUser("emaildelegate@contoso.com");
    emailDelegate.Permissions.InboxFolderPermissionLevel = DelegateFolderPermissionLevel.Editor;
    // Add the delegate to the list of new delegates.
    newDelegates.Add(emailDelegate);
    // Create a mailbox object that represents the mailbox owner.
    Mailbox mailbox = new Mailbox("primary@contoso.com");
    // Call the AddDelegates method to add the delegates to the target mailbox.
    Collection<DelegateUserResponse> response = service.AddDelegates(mailbox, MeetingRequestsDeliveryScope.DelegatesAndSendInformationToMe, newDelegates);
            
    foreach (DelegateUserResponse resp in response)
    {
        // Print out the result and the last eight characters of the item ID.
        Console.WriteLine("For delegate " + resp.DelegateUser.UserId.PrimarySmtpAddress.ToString());
        Console.WriteLine("Result: {0}", resp.Result);
        Console.WriteLine("Error Code: {0}", resp.ErrorCode);
        Console.WriteLine("ErrorMessage: {0}\r\n", resp.ErrorMessage);
        Console.WriteLine("\r\n");
    }
    return response;
}

Agregar delegados mediante EWSAdd delegates by using EWS

En el ejemplo de código siguiente se muestra cómo agregar delegados de correo electrónico, contactos y calendario independientes mediante la operación de EWS de AddDelegate .The following code example shows how to add separate calendar, contact, and email delegates by using the AddDelegate EWS operation. El elemento Mailbox especifica el buzón que se va a modificar y la configuración de permisos de cada delegado se encuentra en el elemento DelegateUser .The mailbox to modify is specified by the Mailbox element, and the permission settings for each delegate are contained in the DelegateUser element. A cada uno de los delegados se le han concedido permisos de editor para su carpeta de destino.Each of the delegates has been granted Editor permissions to their target folder.

También es la solicitud XML que la API administrada de EWS envía cuando se usa el método AddDelegates para Agregar delegados.This is also the XML request that the EWS Managed API sends when you use the AddDelegates method to add delegates.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages"
               xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types"
               xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2007_SP1" />
  </soap:Header>
  <soap:Body>
    <m:AddDelegate>
      <m:Mailbox>
        <t:EmailAddress>primary@contoso.com</t:EmailAddress>
      </m:Mailbox>
      <m:DelegateUsers>
        <t:DelegateUser>
          <t:UserId>
            <t:PrimarySmtpAddress>calendardelegate@contoso.com</t:PrimarySmtpAddress>
          </t:UserId>
          <t:DelegatePermissions>
            <t:CalendarFolderPermissionLevel>Editor</t:CalendarFolderPermissionLevel>
            <t:TasksFolderPermissionLevel>None</t:TasksFolderPermissionLevel>
            <t:InboxFolderPermissionLevel>None</t:InboxFolderPermissionLevel>
            <t:ContactsFolderPermissionLevel>None</t:ContactsFolderPermissionLevel>
            <t:NotesFolderPermissionLevel>None</t:NotesFolderPermissionLevel>
            <t:JournalFolderPermissionLevel>None</t:JournalFolderPermissionLevel>
          </t:DelegatePermissions>
          <t:ReceiveCopiesOfMeetingMessages>false</t:ReceiveCopiesOfMeetingMessages>
          <t:ViewPrivateItems>false</t:ViewPrivateItems>
        </t:DelegateUser>
        <t:DelegateUser>
          <t:UserId>
            <t:PrimarySmtpAddress>contactdelegate@contoso.com</t:PrimarySmtpAddress>
          </t:UserId>
          <t:DelegatePermissions>
            <t:CalendarFolderPermissionLevel>None</t:CalendarFolderPermissionLevel>
            <t:TasksFolderPermissionLevel>None</t:TasksFolderPermissionLevel>
            <t:InboxFolderPermissionLevel>None</t:InboxFolderPermissionLevel>
            <t:ContactsFolderPermissionLevel>Editor</t:ContactsFolderPermissionLevel>
            <t:NotesFolderPermissionLevel>None</t:NotesFolderPermissionLevel>
            <t:JournalFolderPermissionLevel>None</t:JournalFolderPermissionLevel>
          </t:DelegatePermissions>
          <t:ReceiveCopiesOfMeetingMessages>false</t:ReceiveCopiesOfMeetingMessages>
          <t:ViewPrivateItems>false</t:ViewPrivateItems>
        </t:DelegateUser>
        <t:DelegateUser>
          <t:UserId>
            <t:PrimarySmtpAddress>emaildelegate@contoso.com</t:PrimarySmtpAddress>
          </t:UserId>
          <t:DelegatePermissions>
            <t:CalendarFolderPermissionLevel>None</t:CalendarFolderPermissionLevel>
            <t:TasksFolderPermissionLevel>None</t:TasksFolderPermissionLevel>
            <t:InboxFolderPermissionLevel>Editor</t:InboxFolderPermissionLevel>
            <t:ContactsFolderPermissionLevel>None</t:ContactsFolderPermissionLevel>
            <t:NotesFolderPermissionLevel>None</t:NotesFolderPermissionLevel>
            <t:JournalFolderPermissionLevel>None</t:JournalFolderPermissionLevel>
          </t:DelegatePermissions>
          <t:ReceiveCopiesOfMeetingMessages>false</t:ReceiveCopiesOfMeetingMessages>
          <t:ViewPrivateItems>false</t:ViewPrivateItems>
        </t:DelegateUser>
      </m:DelegateUsers>
      <m:DeliverMeetingRequests>DelegatesAndSendInformationToMe</m:DeliverMeetingRequests>
    </m:AddDelegate>
  </soap:Body>
</soap:Envelope>

El servidor responde a la solicitud AddDelegate con un mensaje AddDelegateResponse que incluye un valor de elemento ResponseCode de NoError, lo que indica que los delegados se crearon correctamente.The server responds to the AddDelegate request with an AddDelegateResponse message that includes a ResponseCode element value of NoError, which indicates that the delegates were successfully created.

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <h:ServerVersionInfo MajorVersion="15"
                         MinorVersion="0"
                         MajorBuildNumber="888"
                         MinorBuildNumber="9"
                         Version="V2_10"
                         xmlns:h="https://schemas.microsoft.com/exchange/services/2006/types"
                         xmlns="https://schemas.microsoft.com/exchange/services/2006/types"
                         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <m:AddDelegateResponse ResponseClass="Success"
                           xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages"
                           xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">
      <m:ResponseCode>NoError</m:ResponseCode>
      <m:ResponseMessages>
        <m:DelegateUserResponseMessageType ResponseClass="Success">
          <m:ResponseCode>NoError</m:ResponseCode>
          <m:DelegateUser>
            <t:UserId>
              <t:SID>S-1-5-21-1337771579-694202782-848329751-1535221</t:SID>
              <t:PrimarySmtpAddress>calendardelegate@contoso.com</t:PrimarySmtpAddress>
              <t:DisplayName>calendardelegate</t:DisplayName>
            </t:UserId>
            <t:ReceiveCopiesOfMeetingMessages>false</t:ReceiveCopiesOfMeetingMessages>
            <t:ViewPrivateItems>false</t:ViewPrivateItems>
          </m:DelegateUser>
        </m:DelegateUserResponseMessageType>
        <m:DelegateUserResponseMessageType ResponseClass="Success">
          <m:ResponseCode>NoError</m:ResponseCode>
          <m:DelegateUser>
            <t:UserId>
              <t:SID>S-1-5-21-1337771579-694202782-848329751-1535264</t:SID>
              <t:PrimarySmtpAddress>contactdelegate@contoso.com</t:PrimarySmtpAddress>
              <t:DisplayName>contactdelegate</t:DisplayName>
            </t:UserId>
            <t:ReceiveCopiesOfMeetingMessages>false</t:ReceiveCopiesOfMeetingMessages>
            <t:ViewPrivateItems>false</t:ViewPrivateItems>
          </m:DelegateUser>
        </m:DelegateUserResponseMessageType>
        <m:DelegateUserResponseMessageType ResponseClass="Success">
          <m:ResponseCode>NoError</m:ResponseCode>
          <m:DelegateUser>
            <t:UserId>
              <t:SID>S-1-5-21-1337771579-694202782-848329751-1535223</t:SID>
              <t:PrimarySmtpAddress>emaildelegate@contoso.com</t:PrimarySmtpAddress>
              <t:DisplayName>emaildelegate</t:DisplayName>
            </t:UserId>
            <t:ReceiveCopiesOfMeetingMessages>false</t:ReceiveCopiesOfMeetingMessages>
            <t:ViewPrivateItems>false</t:ViewPrivateItems>
          </m:DelegateUser>
        </m:DelegateUserResponseMessageType>
      </m:ResponseMessages>
    </m:AddDelegateResponse>
  </s:Body>
</s:Envelope>

Quitar delegados mediante la API administrada de EWSRemove delegates by using the EWS Managed API

Puede quitar delegados de un buzón de correo de destino mediante el método de la API administrada de EWS ExchangeService. RemoveDelegates .You can remove delegates from a target mailbox by using the ExchangeService.RemoveDelegates EWS Managed API method. En este ejemplo, se quitan los permisos delegados establecidos en el ejemplo Add a Delegate .In this example, the delegate permissions set in the add a delegate example are removed.

En este ejemplo se supone que el servicio es un objeto ExchangeService válido para el propietario del buzón y que el usuario se ha autenticado en un servidor de Exchange.This example assumes that service is a valid ExchangeService object for the mailbox owner, and that the user has been authenticated to an Exchange server.

public static Collection<DelegateUserResponse> RemoveDelegates(ExchangeService service)
{
    // Create a list to hold the delegates to delete.
    List<UserId> deletedDelegates = new System.Collections.Generic.List<UserId>();
    // Add the delegate to the list of new delegates.
    deletedDelegates.Add("calendardelegate@contoso.com");
    // Add the delegate to the list of new delegates.
    deletedDelegates.Add("contactdelegate@contoso.com");
    // Add the delegate to the list of new delegates.
    deletedDelegates.Add("emaildelegate@contoso.com");
    // Create a mailbox object that represents the mailbox owner.
    Mailbox mailbox = new Mailbox("primary@contoso.com");
    // Call the AddDelegates method to add the delegates to the target mailbox.
    Collection<DelegateUserResponse> response = service.RemoveDelegates(mailbox, deletedDelegates);
    foreach (DelegateUserResponse resp in response)
    {
        // Print out the result and the last eight characters of the item ID.
        Console.WriteLine("Result: {0}", resp.Result);
        Console.WriteLine("Error Code: {0}", resp.ErrorCode);
        Console.WriteLine("ErrorMessage: {0}\r\n", resp.ErrorMessage);
    }
    return response;
}

Quitar delegados mediante EWSRemove delegates by using EWS

Puede quitar delegados de un buzón de correo mediante la operación de EWS de RemoveDelegate .You can remove delegates from a mailbox by using the RemoveDelegate EWS operation. En este ejemplo, se quitan los permisos delegados establecidos en el ejemplo Add a Delegate .In this example, the delegate permissions set in the add a delegate example are removed.

También es la solicitud XML que la API administrada de EWS envía cuando se usa el método RemoveDelegates para quitar delegados.This is also the XML request that the EWS Managed API sends when you use the RemoveDelegates method to remove delegates.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages"
               xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types"
               xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2007_SP1" />
  </soap:Header>
  <soap:Body>
    <m:RemoveDelegate>
      <m:Mailbox>
        <t:EmailAddress>primary@contoso.com</t:EmailAddress>
      </m:Mailbox>
      <m:UserIds>
        <t:UserId>
          <t:PrimarySmtpAddress>calendardelegate@contoso.com</t:PrimarySmtpAddress>
        </t:UserId>
        <t:UserId>
          <t:PrimarySmtpAddress>contactdelegate@contoso.com</t:PrimarySmtpAddress>
        </t:UserId>
        <t:UserId>
          <t:PrimarySmtpAddress>emaildelegate@contoso.com</t:PrimarySmtpAddress>
        </t:UserId>
      </m:UserIds>
    </m:RemoveDelegate>
  </soap:Body>
</soap:Envelope>

El servidor responde a la solicitud RemoveDelegate con un mensaje AddDelegateResponse que incluye un valor de elemento ResponseCode de NoError, lo que indica que los delegados se quitaron correctamente.The server responds to the RemoveDelegate request with a AddDelegateResponse message that includes a ResponseCode element value of NoError, which indicates that the delegates were successfully removed.

Pasos siguientesNext steps

Después de agregar delegados a las carpetas de calendario, correo electrónico y tareas, el delegado puede tener acceso a los elementos de las carpetas.After you add delegates to calendar, email, and task folders, the delegate can access the items in the folders. Para obtener más información, vea los siguientes artículos:To learn more, see the following articles:

Si las carpetas para las que agregó delegados incluyen carpetas secundarias creadas antes de conceder el acceso delegado, el delegado no podrá obtener acceso a esas carpetas sin permisos adicionales.If the folders for which you added delegates include child folders that were created before you granted the delegate access, the delegate will not be able to access those folders without additional permissions. Para agregar estos permisos, o modificar permisos para otras carpetas, vea establecer los permisos de carpeta para otro usuario mediante EWS en Exchange.To add these permissions, or modify permissions for any other folders, see Set folder permissions for another user by using EWS in Exchange.

Vea tambiénSee also