MarkAsJunk operation
Find information about the MarkAsJunk EWS operation.
The MarkAsJunk operation adds and removes users from the blocked email list and moves email messages to the Junk Email folder.
This operation was introduced in Exchange Server 2013.
Using the MarkAsJunk operation
The MarkAsJunk operation contains two Boolean options to indicate whether an email sender should be added to the blocked sender list and whether the target email message should be moved to the default Junk Email folder or the Inbox folder. The actions are determined by the values of the IsJunk and MoveItem attributes. The following are the possible actions based on the value combinations for the IsJunk and MoveItem attributes:
If the IsJunk attribute is set to true, and the MoveItem attribute is set to true, the sender of the target email message is added to the blocked sender list and the email message is moved to the Junk Dmail folder.
If the IsJunk attribute is set to true, and the MoveItem attribute is set to false, the sender of the target email message is added to the blocked sender list and the email message is not moved from the folder.
If the IsJunk attribute is set to false, and the MoveItem attribute is set to true, the sender of the target email messageis removed from the blocked sender list and the email message is moved to the Inbox folder.
If the IsJunk attribute is set to false, and the MoveItem attribute is set to false, the sender of the target email message is removed from the blocked sender list and the email message is not moved from the folder.
Important
The contents of the blocked sender list are not discoverable from EWS. If a sender is added to the blocked sender list, you need to keep a copy of an email message sent by the blocked sender to unblock the sender in the future.
MarkAsJunk operation SOAP headers
The MarkAsJunk operation can use the SOAP headers that are listed in the following table.
Header name | Element | Description |
---|---|---|
Impersonation |
ExchangeImpersonation |
Identifies the user whom the client application is impersonating. This header is applicable to a request. |
MailboxCulture |
MailboxCulture |
Identifies the culture, as defined in RFC 3066, "Tags for the Identification of Languages", to be used to access the mailbox. This header is applicable to a request. |
RequestVersion |
RequestServerVersion |
Identifies the schema version for the operation request. This header is applicable to a request. |
ServerVersion |
ServerVersionInfo |
Identifies the version of the server that responded to the request. This header is applicable to a response. |
MarkAsJunk operation request example: Add a sender to the blocked sender list
The following example of a MarkAsJunk operation request shows how to add the sender of an email to the blocked sender list and move the email to the junk mail folder. The MarkAsJunk operation accepts the unique email message identifier to identify the email that is used to reference the sender that is added to the blocked sender list.
Note
All item identifiers and change keys in this article have been shortened to preserve readability.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:soap="http://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="AAMkAD=" ChangeKey="CQAAABYA" />
</m:ItemIds>
</m:MarkAsJunk>
</soap:Body>
</soap:Envelope>
The request SOAP body contains the following elements:
Successful MarkAsJunk operation response
The following example shows a successful response to a MarkAsJunk operation request to add a sender to the blocked sender list and move the email message to the Junk Email folder.
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="15"
MinorVersion="0"
MajorBuildNumber="545"
MinorBuildNumber="11"
Version="Exchange2013"
xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns="http://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="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:MarkAsJunkResponseMessage ResponseClass="Success">
<m:ResponseCode>NoError</m:ResponseCode>
<m:MovedItemId Id="AAMkAD=" ChangeKey="CQAAABYu" />
</m:MarkAsJunkResponseMessage>
</m:ResponseMessages>
</m:MarkAsJunkResponse>
</s:Body>
</s:Envelope>
The response SOAP body contains the following elements:
MarkAsJunk operation request example: Remove a sender from the blocked sender list
The following example of a MarkAsJunk operation request shows how to remove the sender of an email message from the blocked sender list and move the email message to the Inbox folder. You need to keep an email message sent by the blocked sender to remove the sender from the blocked sender list. The sender's email address is associated with email messages that have been sent by the sender. Removing a sender from the blocked sender list will not succeed if the reference email message no longer exists in the user's mailbox. The item identifier used to associate an email message with its sender must be associated with an item that exists in the Exchange mailbox. We recommend that you create a hidden folder to store items sent by previously blocked senders so that the senders can be unblocked from the client application. In the event that an item has been removed from the Exchange mailbox, an administrator has to use the Exchange Management Console to access the blocked sender list to remove a sender from the list. For information about how to unblock a user by using the Exchange Management Console, see How to configure the safe senders and blocked senders settings in Office 365.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2013" />
</soap:Header>
<soap:Body>
<m:MarkAsJunk IsJunk="false" MoveItem="true">
<m:ItemIds>
<t:ItemId Id="AAMkAD=" ChangeKey="CQAAABYu" />
</m:ItemIds>
</m:MarkAsJunk>
</soap:Body>
</soap:Envelope>
A successful response for removing a sender from the blocked sender list is the same as the response for adding a sender to the blocked sender list.
The request SOAP body contains the following elements:
MarkAsJunk operation error response
The following example shows an error response to a MarkAsJunk operation request. This is a response to a request to add or remove a sender from the blocked sender list when the email message specified by the item identifier no longer exists in the mailbox.
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="15"
MinorVersion="0"
MajorBuildNumber="545"
MinorBuildNumber="11"
Version="Exchange2013"
xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns="http://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="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:MarkAsJunkResponseMessage ResponseClass="Error">
<m:MessageText>The specified object was not found in the store.</m:MessageText>
<m:ResponseCode>ErrorItemNotFound</m:ResponseCode>
<m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
</m:MarkAsJunkResponseMessage>
</m:ResponseMessages>
</m:MarkAsJunkResponse>
</s:Body>
</s:Envelope>
The error response SOAP body contains the following elements:
See also
GetItem operation GetItem operation