Adicionar e remover endereços de email da lista de remetentes bloqueados usando o EWS no ExchangeAdd and remove email addresses from the Blocked Senders List by using EWS in Exchange

Descubra como usar a API gerenciada do EWS ou o EWS para adicionar endereços de email e removê-los da lista de remetentes bloqueados.Find out how to use the EWS Managed API or EWS to add email addresses to and remove them from the Blocked Senders List.

A lista de remetentes bloqueados nas opções de lixo eletrônico de um usuário oferece uma maneira de mover todas as mensagens de email de remetentes especificados para a pasta lixo eletrônico.The Blocked Senders List in a user's Junk Email options provides a way to move all email messages from specified senders to the Junk Email folder. Você pode habilitar a API gerenciada do EWS ou o aplicativo EWS para adicionar endereços de email ou removê-los da lista de remetentes bloqueados.You can enable your EWS Managed API or EWS application to add email addresses to or remove them from the Blocked Senders List.

Observe que uma mensagem do endereço de email deve existir na caixa de correio do usuário antes que você possa adicionar o endereço de email ou removê-lo da lista de remetentes bloqueados.Note that a message from the email address must exist in the user's mailbox before you can add the email address to or remove it from the Blocked Senders List. O método ExchangeService. MarkAsJunk EWS Managed API e a operação MarkAsJunk EWS usam uma coleção de IDs de item.The ExchangeService.MarkAsJunk EWS Managed API method and the MarkAsJunk EWS operation use a collection of item IDs. As IDs de item na coleção indicam mensagens na caixa de correio para a qual o status de lixo eletrônico deve ser alterado.The item IDs in the collection indicate messages in the mailbox for which the junk mail status should be changed.

Você pode usar os cmdlets Get-MailboxJunkEmailConfiguration e set-MailboxJunkEmailConfiguration do Shell de gerenciamento do Exchange para acessar a lista de remetentes bloqueados diretamente.You can use the Get-MailboxJunkEmailConfiguration and Set-MailboxJunkEmailConfiguration Exchange Management Shell cmdlets to access the Blocked Senders List directly.

Adicionar um endereço de email ou removê-lo da lista de remetentes bloqueados usando a API gerenciada do EWSAdd an email address to or remove it from the Blocked Senders List by using the EWS Managed API

Para adicionar o remetente de uma mensagem de email à lista de remetentes bloqueados, use o método MarkAsJunk e defina o parâmetro isjunk como true.To add the sender of an email message to the Blocked Senders List, use the MarkAsJunk method and set the isJunk parameter to true. Para remover o remetente de uma mensagem de email da lista de remetentes bloqueados, defina o parâmetro isjunk como false.To remove the sender of an email message from the Blocked Senders List, set the isJunk parameter to false.

O exemplo a seguir mostra como usar o método MarkAsJunk para alterar o status de lixo eletrônico de uma mensagem.The following example shows how to use the MarkAsJunk method to change the junk status of a message.

private static void MarkMessageAsJunk(ExchangeService service, ItemId messageId, bool isJunk, bool moveItem)
{
    List<ItemId> junkItemIds = new List<ItemId>();
    junkItemIds.Add(messageId);
    ServiceResponseCollection<MarkAsJunkResponse> responseCollection = null;
    try
    {
        // If isJunk is true, the sender of the email message is added to 
        // the Blocked Senders List. If isJunk is false, the sender is removed
        // from the list (if present).
        responseCollection = service.MarkAsJunk(junkItemIds, isJunk, moveItem);
    }
    catch (ServiceResponseException ex)
    {
        Console.WriteLine("Error marking item as junk: {0}", ex.ErrorCode);
        return;
    }
    foreach (MarkAsJunkResponse response in responseCollection)
    {
        if (response.Result == ServiceResult.Success)
        {
            Console.WriteLine("Successfully marked message as {0}junk.", isJunk ? "": "NOT ");
            if (moveItem)
            {
                Console.WriteLine("New item ID: {0}", response.MovedItemId.ToString());
            }
        }
        else
        {
            Console.WriteLine("[{0}]: {1}", response.Result.ToString(),
                response.ErrorCode.ToString());
        }
    }
}

Adicionar um endereço de email ou removê-lo da lista de remetentes bloqueados usando o EWSAdd an email address to or remove it from the Blocked Senders List by using EWS

A solicitação SOAP do EWS a seguir marca um item como lixo eletrônico Configurando o atributo isjunk no elemento MarkAsJunk como true.The following EWS SOAP request marks an item as junk by setting the IsJunk attribute on the MarkAsJunk element to true. Ele também move a mensagem para a pasta lixo eletrônico definindo o atributo MoveItem no elemento MarkAsJunk como true.It also moves the message to the Junk Email folder by setting the MoveItem attribute on the MarkAsJunk element to true.

<?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="Exchange2013" />
  </soap:Header>
  <soap:Body>
    <m:MarkAsJunk IsJunk="true" MoveItem="true">
      <m:ItemIds>
        <t:ItemId Id="AAMkADg1OWUwODcyLTg4M2MtNDAyMS05YjI0LTI5ZGM5OTU4Njk3YwBGAAAAAADPriAxh444TpHj2GoQxWQNBwAN+VjmVZl5Rq1ymCq5eFKOAAAAAAENAAAN+VjmVZl5Rq1ymCq5eFKOAAAAAAEuAAA=" 
            ChangeKey="CQAAABYAAAAN+VjmVZl5Rq1ymCq5eFKOAAAAAADi" />
      </m:ItemIds>
    </m:MarkAsJunk>
  </soap:Body>
</soap:Envelope>

A resposta SOAP do EWS a seguir mostra a resposta bem-sucedida.The following EWS SOAP response shows the successful response. O elemento MovedItemId na resposta contém a ID do item após ele ter sido movido.The MovedItemId element in the response contains the item ID for the item after it was moved.

<?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="712" MinorBuildNumber="22" Version="V2_3" 
        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:MarkAsJunkResponse xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" 
        xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">
      <m:ResponseMessages>
        <m:MarkAsJunkResponseMessage ResponseClass="Success">
          <m:ResponseCode>NoError</m:ResponseCode>
          <m:MovedItemId Id="AAMkADg1OWUwODcyLTg4M2MtNDAyMS05YjI0LTI5ZGM5OTU4Njk3YwBGAAAAAADPriAxh444TpHj2GoQxWQNBwAN+VjmVZl5Rq1ymCq5eFKOAAAAAAEbAAAN+VjmVZl5Rq1ymCq5eFKOAAAE59DIAAA="
              ChangeKey="CQAAABYAAAAN+VjmVZl5Rq1ymCq5eFKOAAAE59E+" />
        </m:MarkAsJunkResponseMessage>
      </m:ResponseMessages>
    </m:MarkAsJunkResponse>
  </s:Body>
</s:Envelope>

Confira tambémSee also