共用方式為


快速入門:使用管理用戶端程式庫管理 Azure 通訊服務中的網域禁止清單

重要

本文所述的功能目前處於公開預覽狀態。 此預覽版本沒有服務等級協定,不建議用於處理生產工作負載。 可能不支援特定功能,或可能已經限制功能。 如需詳細資訊,請參閱 Microsoft Azure 預覽版增補使用條款

本快速入門涵蓋使用 Azure 通訊服務管理用戶端程式庫在 Azure 通訊服務中管理網域禁止清單的流程。

必要條件

安裝必要套件

dotnet add package Azure.ResourceManager.Communication
dotnet add package Azure.Identity

初始化管理用戶端

使用您的網域和電子郵件資源所屬之訂用帳戶的訂用帳戶識別碼來設定環境變數 AZURE_SUBSCRIPTION_ID。 執行程式碼範例以初始化管理用戶端。

using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Communication;

ArmClient client = new ArmClient(new DefaultAzureCredential());

將禁止清單新增至網域資源

若要防止電子郵件訊息傳送至特定地址,第一個步驟是在網域資源中設定禁止清單。

使用資源群組名稱、電子郵件服務名稱和您想要為其建立禁止清單的網域資源名稱來更新範例程式碼。 透過瀏覽至設定必要條件時所建立的網域資源,在入口網站中尋找此資訊。 資源的標題為 <your-email-service-name>/<your-domain-name>。 在網域資源概觀的 [基本資訊] 區段中,尋找資源群組名稱和訂用帳戶識別碼。 為禁止清單資源選擇任何名稱,並同樣更新範例中的該欄位。

針對清單名稱,請確定其與您想要禁止電子郵件寄件者之 MailFrom 地址的寄件者使用者名稱相同。 您可以在入口網站的網域資源之 [MailFrom 地址] 區段中找到這些 MailFrom 地址。 例如,您可能有一個 MailFrom 地址,看起來像「donotreply@xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azurecomm.net」。 此地址的寄件者使用者名稱會是「donotreply」,因此應該使用「donotreply」的清單名稱。

範例程式碼會建立禁止清單,並將其儲存在 suppressionListResource 變數中以供日後作業使用。

string subscriptionId = "<your-subscription-id>"; // Found in the essentials section of the domain resource portal overview
string resourceGroupName = "<your-resource-group-name>"; // Found in the essentials section of the domain resource portal overview
string emailServiceName = "<your-email-service-name>"; // Found in the first part of the portal domain resource title
string domainResourceName = "<your-domain-name>"; // Found in the second part of the portal domain resource title
string suppressionListResourceName = "<your-suppression-list-resource-name>";

ResourceIdentifier suppressionListResourceId = SuppressionListResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, emailServiceName, domainResourceName, suppressionListResourceName);
SuppressionListResource suppressionListResource = client.GetSuppressionListResource(suppressionListResourceId);

SuppressionListResourceData suppressionListData = new SuppressionListResourceData()
{
    ListName = "<your-sender-username>", // Should match the sender username of the MailFrom address you would like to suppress emails from
};

suppressionListResource.Update(WaitUntil.Completed, suppressionListData);

如果您想要禁止特定網域中所有寄件者使用者名稱的電子郵件,則您可以在清單名稱中傳遞空白字元。

SuppressionListResourceData suppressionListData = new SuppressionListResourceData()
{
    ListName = "",
};

suppressionListResource.Update(WaitUntil.Completed, suppressionListData);

將地址新增至禁止清單

設定禁止清單之後,您現在即可以新增要阻止傳送地址郵件的特定電子郵件地址。

使用禁止清單地址識別碼更新範例程式碼。 您新增的每個禁止清單地址識別碼都必須是唯一的。 我們建議使用 GUID。 同時更新您要禁止接收訊息的電子郵件地址。

若要將多個地址新增至禁止清單,則您必須多次重複此範例程式碼。

string suppressionListAddressId = "<your-suppression-list-address-id>";

ResourceIdentifier suppressionListAddressResourceId = SuppressionListAddressResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, emailServiceName, domainResourceName, suppressionListResourceName, suppressionListAddressId);
SuppressionListAddressResource suppressionListAddressResource = client.GetSuppressionListAddressResource(suppressionListAddressResourceId);

SuppressionListAddressResourceData suppressionListAddressData = new SuppressionListAddressResourceData()
{
    Email = "<email-address-to-suppress>" // Should match the email address you would like to block from receiving your messages
};

suppressionListAddressResource.Update(WaitUntil.Completed, suppressionListAddressData);

您現在可以嘗試從通訊服務資源的 TryEmail 區段,或使用其中一個電子郵件 SDK 將電子郵件傳送至禁止的地址。 請務必使用 MailFrom 地址傳送電子郵件,並使用您選擇要禁止的寄件者使用名稱。 您的電子郵件不會傳送至已禁止的地址。

如果您嘗試從未受禁止的電子郵件寄件者使用名稱傳送電子郵件,則該電子郵件仍會成功傳送。

從禁止清單中移除地址

若要從禁止清單中移除地址,請建立 SuppressionListAddressResource,如先前的範例程式碼所示,並呼叫 Delete 方法。

suppressionListAddressResource.Delete(WaitUntil.Completed);

您現在可以嘗試從通訊服務資源的 TryEmail 區段,或使用其中一個電子郵件 SDK 將電子郵件傳送至禁止的地址。 請務必使用 MailFrom 地址傳送電子郵件,並使用您選擇要禁止的寄件者使用名稱。 您的電子郵件會成功傳送至先前禁止的地址。

從網域資源移除禁止清單

若要從網域資源中移除禁止清單,請建立 SuppressionListResource,如先前的範例程式碼所示,並呼叫 Delete 方法。

suppressionListResource.Delete(WaitUntil.Completed);

必要條件

安裝必要套件

npm install @azure/arm-communication
npm install @azure/identity

初始化管理用戶端

將範例程式碼中的欄位取代為您的網域和電子郵件資源所屬之訂用帳戶的訂用帳戶識別碼。 執行程式碼範例以初始化管理用戶端。

const { CommunicationServiceManagementClient } = require("@azure/arm-communication");
const { DefaultAzureCredential } = require("@azure/identity");

const credential = new DefaultAzureCredential();
const subscriptionId = "<your-subscription-id>";

const client = new CommunicationServiceManagementClient(credential, subscriptionId);

將禁止清單新增至網域資源

若要防止電子郵件訊息傳送至特定地址,第一個步驟是在網域資源中設定禁止清單。

使用資源群組名稱、電子郵件服務名稱和您想要為其建立禁止清單的網域資源名稱來更新範例程式碼。 透過瀏覽至設定必要條件時所建立的網域資源,在入口網站中尋找此資訊。 資源的標題為 <your-email-service-name>/<your-domain-name>。 在網域資源概觀的 [基本資訊] 區段中,尋找資源群組名稱和訂用帳戶識別碼。 為禁止清單資源選擇任何名稱,並同樣更新範例中的該欄位。

針對清單名稱,請確定其與您想要禁止電子郵件寄件者之 MailFrom 地址的寄件者使用者名稱相同。 您可以在入口網站的網域資源之 [MailFrom 地址] 區段中找到這些 MailFrom 地址。 例如,您可能有一個 MailFrom 地址,看起來像「donotreply@xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azurecomm.net」。 此地址的寄件者使用者名稱會是「donotreply」,因此應該使用「donotreply」的清單名稱。

const resourceGroupName = "<your-resource-group-name>"; // Found in the essentials section of the domain resource portal overview
const emailServiceName = "<your-email-service-name>"; // Found in the first part of the portal domain resource title
const domainResourceName = "<your-domain-name>"; // Found in the second part of the portal domain resource title
const suppressionListResourceName = "<your-suppression-list-resource-name>";

parameters = { 
    "listName": "<your-sender-username>", // Should match the sender username of the MailFrom address you would like to suppress emails from
}

await client.suppressionLists.createOrUpdate(
    resourceGroupName,
    emailServiceName,
    domainResourceName,
    suppressionListResourceName,
    parameters
);

如果您想要禁止特定網域中所有寄件者使用者名稱的電子郵件,則您可以在清單名稱中傳遞空白字元。

parameters = { 
    "listName": "",
}

await client.suppressionLists.createOrUpdate(
    resourceGroupName,
    emailServiceName,
    domainResourceName,
    suppressionListResourceName,
    parameters
);

將地址新增至禁止清單

設定禁止清單之後,您現在即可以新增要阻止傳送地址郵件的特定電子郵件地址。

使用禁止清單地址識別碼更新範例程式碼。 您新增的每個禁止清單地址識別碼都必須是唯一的。 我們建議使用 GUID。 同時更新您要禁止接收訊息的電子郵件地址。

若要將多個地址新增至禁止清單,則您必須多次重複此範例程式碼。

const suppressionListAddressId = "<your-suppression-list-address-id>";

parameters = { 
    "email": "<email-address-to-suppress>" // Should match the email address you would like to block from receiving your messages
}

await client.suppressionListAddresses.createOrUpdate(
    resourceGroupName,
    emailServiceName,
    domainResourceName,
    suppressionListResourceName,
    suppressionListAddressId,
    parameters
);

您現在可以嘗試從通訊服務資源的 TryEmail 區段,或使用其中一個電子郵件 SDK 將電子郵件傳送至禁止的地址。 請務必使用 MailFrom 地址傳送電子郵件,並使用您選擇要禁止的寄件者使用名稱。 您的電子郵件不會傳送至已禁止的地址。

如果您嘗試從未受禁止的電子郵件寄件者使用名稱傳送電子郵件,則該電子郵件仍會成功傳送。

從禁止清單中移除地址

suppressionListAddresses 上呼叫 delete 方法,以從禁止清單中移除地址。

await client.suppressionListAddresses.delete(
    resourceGroupName,
    emailServiceName,
    domainResourceName,
    suppressionListResourceName,
    suppressionListAddressId
);

您現在可以嘗試從通訊服務資源的 TryEmail 區段,或使用其中一個電子郵件 SDK 將電子郵件傳送至禁止的地址。 請務必使用 MailFrom 地址傳送電子郵件,並使用您選擇要禁止的寄件者使用名稱。 您的電子郵件會成功傳送至先前禁止的地址。

從網域資源移除禁止清單

suppressionList 上呼叫 delete 方法,以從網域資源中移除禁止清單。

await client.suppressionLists.delete(
    resourceGroupName,
    emailServiceName,
    domainResourceName,
    suppressionListResourceName
);

必要條件

安裝必要套件

將下列相依性新增至您的 pom.xml

<dependency>
    <groupId>com.azure.resourcemanager</groupId>
    <artifactId>azure-resourcemanager-communication</artifactId>
    <version>2.2.0</version>
</dependency>
<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-identity</artifactId>
    <version>1.11.1</version>
</dependency>

初始化管理用戶端

使用您的網域和電子郵件資源所屬之訂用帳戶的訂用帳戶識別碼來設定環境變數 AZURE_SUBSCRIPTION_ID

在檔案頂端新增下列匯入。

import com.azure.core.credential.TokenCredential;
import com.azure.core.management.AzureEnvironment;
import com.azure.core.management.profile.AzureProfile;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.resourcemanager.communication.CommunicationManager;

執行程式碼範例以初始化管理用戶端。

AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
TokenCredential credential = new DefaultAzureCredentialBuilder()
        .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
        .build();

CommunicationManager manager = CommunicationManager
        .authenticate(credential, profile);

將禁止清單新增至網域資源

若要防止電子郵件訊息傳送至特定地址,第一個步驟是在網域資源中設定禁止清單。

使用資源群組名稱、電子郵件服務名稱和您想要為其建立禁止清單的網域資源名稱來更新範例程式碼。 透過瀏覽至設定必要條件時所建立的網域資源,在入口網站中尋找此資訊。 資源的標題為 <your-email-service-name>/<your-domain-name>。 在網域資源概觀的 [基本資訊] 區段中,尋找資源群組名稱和訂用帳戶識別碼。 為禁止清單資源選擇任何名稱,並同樣更新範例中的該欄位。

針對清單名稱,請確定其與您想要禁止電子郵件寄件者之 MailFrom 地址的寄件者使用者名稱相同。 您可以在入口網站的網域資源之 [MailFrom 地址] 區段中找到這些 MailFrom 地址。 例如,您可能有一個 MailFrom 地址,看起來像「donotreply@xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azurecomm.net」。 此地址的寄件者使用者名稱會是「donotreply」,因此應該使用「donotreply」的清單名稱。

String resourceGroupName = "<your-resource-group-name>"; // Found in the essentials section of the domain resource portal overview
String emailServiceName = "<your-email-service-name>"; // Found in the first part of the portal domain resource title
String domainResourceName = "<your-domain-name>"; // Found in the second part of the portal domain resource title
String suppressionListResourceName = "<your-suppression-list-resource-name>";

manager.suppressionLists().define(suppressionListResourceName)
    .withExistingDomain(resourceGroupName, emailServiceName, domainResourceName)
    .withListName("<your-sender-username>") // Should match the sender username of the MailFrom address you would like to suppress emails from
    .create();

如果您想要禁止特定網域中所有寄件者使用者名稱的電子郵件,則您可以在清單名稱中傳遞空白字元。

manager.suppressionLists().define(suppressionListResourceName)
    .withExistingDomain(resourceGroupName, emailServiceName, domainResourceName)
    .withListName("")
    .create();

將地址新增至禁止清單

設定禁止清單之後,您現在即可以新增要阻止傳送地址郵件的特定電子郵件地址。

使用禁止清單地址識別碼更新範例程式碼。 您新增的每個禁止清單地址識別碼都必須是唯一的。 我們建議使用 GUID。 同時更新您要禁止接收訊息的電子郵件地址。

若要將多個地址新增至禁止清單,則您必須多次重複此範例程式碼。

String suppressionListAddressId = "<your-suppression-list-address-id>";

manager.suppressionListAddresses().define(suppressionListAddressId)
    .withExistingSuppressionList(resourceGroupName, emailServiceName, domainResourceName, suppressionListResourceName)
    .withEmail("<email-address-to-suppress>") // Should match the email address you would like to block from receiving your messages
    .create();

您現在可以嘗試從通訊服務資源的 TryEmail 區段,或使用其中一個電子郵件 SDK 將電子郵件傳送至禁止的地址。 請務必使用 MailFrom 地址傳送電子郵件,並使用您選擇要禁止的寄件者使用名稱。 您的電子郵件不會傳送至已禁止的地址。

如果您嘗試從未受禁止的電子郵件寄件者使用名稱傳送電子郵件,則該電子郵件仍會成功傳送。

從禁止清單中移除地址

suppressionListAddresses 上呼叫 delete 方法,以從禁止清單中移除地址。

manager.suppressionListAddresses()
    .delete(resourceGroupName, emailServiceName, domainResourceName, suppressionListResourceName, suppressionListAddressId);

您現在可以嘗試從通訊服務資源的 TryEmail 區段,或使用其中一個電子郵件 SDK 將電子郵件傳送至禁止的地址。 請務必使用 MailFrom 地址傳送電子郵件,並使用您選擇要禁止的寄件者使用名稱。 您的電子郵件會成功傳送至先前禁止的地址。

從網域資源移除禁止清單

suppressionLists 上呼叫 delete 方法,以從網域資源中移除禁止清單。

manager.suppressionLists()
    .delete(resourceGroupName, emailServiceName, domainResourceName, suppressionListResourceName);

必要條件

安裝必要套件

pip install azure-mgmt-communication
pip install azure-identity

初始化管理用戶端

使用您的網域和電子郵件資源所屬之訂用帳戶的訂用帳戶識別碼來設定環境變數 AZURE_SUBSCRIPTION_ID。 執行程式碼範例以初始化管理用戶端。

from azure.mgmt.communication import CommunicationServiceManagementClient
from azure.identity import DefaultAzureCredential

credential = DefaultAzureCredential()
subscription_id = "<your-subscription-id>"

mgmt_client = CommunicationServiceManagementClient(credential, subscription_id)

將禁止清單新增至網域資源

若要防止電子郵件訊息傳送至特定地址,第一個步驟是在網域資源中設定禁止清單。

使用資源群組名稱、電子郵件服務名稱和您想要為其建立禁止清單的網域資源名稱來更新範例程式碼。 透過瀏覽至設定必要條件時所建立的網域資源,在入口網站中尋找此資訊。 資源的標題為 <your-email-service-name>/<your-domain-name>。 在網域資源概觀的 [基本資訊] 區段中,尋找資源群組名稱和訂用帳戶識別碼。 為禁止清單資源選擇任何名稱,並同樣更新範例中的該欄位。

針對清單名稱,請確定其與您想要禁止電子郵件寄件者之 MailFrom 地址的寄件者使用者名稱相同。 您可以在入口網站的網域資源之 [MailFrom 地址] 區段中找到這些 MailFrom 地址。 例如,您可能有一個 MailFrom 地址,看起來像「donotreply@xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azurecomm.net」。 此地址的寄件者使用者名稱會是「donotreply」,因此應該使用「donotreply」的清單名稱。

resource_group_name = "<your-resource-group-name>"; # Found in the essentials section of the domain resource portal overview
email_service_name = "<your-email-service-name>"; # Found in the first part of the portal domain resource title
domain_resource_name = "<your-domain-name>"; # Found in the second part of the portal domain resource title
suppression_list_resource_name = "<your-suppression-list-resource-name>";

mgmt_client.suppression_lists.create_or_update(
    resource_group_name,
    email_service_name,
    domain_resource_name,
    suppression_list_resource_name,
    parameters={
        "properties": {
            "listName": "<your-sender-username>" # Should match the sender username of the MailFrom address you would like to suppress emails from
        }
    },
)

如果您想要禁止特定網域中所有寄件者使用者名稱的電子郵件,則您可以在清單名稱中傳遞空白字元。

mgmt_client.suppression_lists.create_or_update(
    resource_group_name,
    email_service_name,
    domain_resource_name,
    suppression_list_resource_name,
    parameters={
        "properties": {
            "listName": ""
        }
    },
)

將地址新增至禁止清單

設定禁止清單之後,您現在即可以新增要阻止傳送地址郵件的特定電子郵件地址。

使用禁止清單地址識別碼更新範例程式碼。 您新增的每個禁止清單地址識別碼都必須是唯一的。 我們建議使用 GUID。 同時更新您要禁止接收訊息的電子郵件地址。

若要將多個地址新增至禁止清單,則您必須多次重複此範例程式碼。

suppression_list_address_id = "<your-suppression-list-address-id>";

mgmt_client.suppression_list_addresses.create_or_update(
    resource_group_name,
    email_service_name,
    domain_resource_name,
    suppression_list_resource_name,
    suppression_list_address_id,
    parameters={
        "properties": {
            "email": "<email-address-to-suppress>" # Should match the email address you would like to block from receiving your messages
        }
    },
)

您現在可以嘗試從通訊服務資源的 TryEmail 區段,或使用其中一個電子郵件 SDK 將電子郵件傳送至禁止的地址。 請務必使用 MailFrom 地址傳送電子郵件,並使用您選擇要禁止的寄件者使用名稱。 您的電子郵件不會傳送至已禁止的地址。

如果您嘗試從未受禁止的電子郵件寄件者使用名稱傳送電子郵件,則該電子郵件仍會成功傳送。

從禁止清單中移除地址

suppression_list_addresses 上呼叫 delete 方法,以從禁止清單中移除地址。

mgmt_client.suppression_list_addresses.delete(
    resource_group_name,
    email_service_name,
    domain_resource_name,
    suppression_list_resource_name,
    suppression_list_address_id
)

您現在可以嘗試從通訊服務資源的 TryEmail 區段,或使用其中一個電子郵件 SDK 將電子郵件傳送至禁止的地址。 請務必使用 MailFrom 地址傳送電子郵件,並使用您選擇要禁止的寄件者使用名稱。 您的電子郵件會成功傳送至先前禁止的地址。

從網域資源移除禁止清單

suppression_lists 上呼叫 delete 方法,以從網域資源中移除禁止清單。

mgmt_client.suppression_lists.delete(
    resource_group_name,
    email_service_name,
    domain_resource_name,
    suppression_list_resource_name
)