Update the Blocklist
The EasyLife 365 Mail API facilitates the direct updating of the mail blocklists. The blocklist feature prevents end-users from creating resources that match or contain blocklist terms. Blocklist terms are either specific email prefixes or simple wildcard terms using an asterisk (*) to denote multiple characters. For instance, an organization might want to avoid using email addresses that use common prefixes such as admin@, marketing@, sales@, and other common email prefixes to help reduce unsolicited emails and other exploits.
Permissions
Permission Type | Permissions (Scope) |
---|---|
Delegated (work or school account) | https://api.insiders.easylife365.cloud/admin/Mail.Blocklist.Write |
Application | Not supported. |
HTTP Request
GET https://api.insiders.easylife365.cloud/admin/v1/blocklist
Content-Type: application/json
HTTP Request Headers
Header | Value |
---|---|
Authorization | Bearer token. (Required) |
Content-Type | application/json |
In this example, we demonstrate how to replace the blocklist with an updated list.
Request Body
Property | Type | Description |
---|---|---|
blocklist | Array | Array of blocklist terms |
Response
Upon executing the request, with an array of updated blocklists. A sample payload might look like this.
[ "admin", "info", "marketing", "admin*", "*test*", "*user" ]
Example 1: Update the Blocklist
This example updates the blocklist with a new list of prefixes. Please note that this method acts on the entire blocklist, replacing all the existing values.
Request
PUT https://api.insiders.easylife365.cloud/admin/v1/blocklist
Content-Type: application/json
[ "admin", "info", "marketing", "admin*", "*test*", "*user" ]
Response
[ "admin", "info", "marketing", "admin*", "*test*", "*user" ]
Example 2: Update the Blocklist using PowerShell
The following example demonstrates updating the blocklist using PowerShell. Before executing the script, ensure you've registered an application and obtained the TenantId and ClientId. Also, retrieve the correct scope from this document.
Import-Module MSAL.PS
$msalParam = @{
tenantId = "[TENANT_ID]"
clientId = "[CLIENT_ID]"
scopes = "[SCOPE]"
}
$uri = "[URI]"
# Get JWT authentication token.
if($token){
$token = Get-MsalToken @msalParam -Silent
} else {
$token = Get-MsalToken @msalParam -DeviceCode
}
# Create object with values to pass to the API.
$body = @(
"admin",
"info",
"marketing",
"admin*",
"*test*",
"*user"
)
# Invoke the API and capture responses.
$jsonBody = $body | ConvertTo-Json -Depth 5 -Compress
$encodedBody = [System.Text.Encoding]::UTF8.GetBytes($jsonBody)
$headers = @{
"Authorization"= "Bearer $($token.AccessToken)"
"Content-Type" = "application/json"
}
Write-Information "Setting the blocklist to: $jsonBody" -InformationAction Continue
Invoke-RestMethod -Method PUT -Uri $uri -Headers $headers -Body $encodedBody