你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
本文介绍如何使用 Azure 通信服务管理客户端库在 Azure 通信服务中添加和删除发件人地址。
先决条件
- 拥有有效订阅的 Azure 帐户。 免费创建帐户。
- 用于预配域的 Azure 电子邮件通信服务资源已准备好。 开始创建电子邮件通信资源。
- 预配了 Azure 托管域 或 自定义域 ,并准备好发送电子邮件。
- 我们使用 服务主体进行身份验证。 将 Microsoft Entra ID 应用程序的客户端 ID、租户 ID 和客户端机密的值设置为以下环境变量:
AZURE_CLIENT_ID
、AZURE_TENANT_ID
和AZURE_CLIENT_SECRET
。
安装必需包
dotnet add package Azure.ResourceManager.Communication
初始化管理客户端
使用你的域和电子邮件资源所位于的订阅的订阅 ID 设置环境变量 AZURE_SUBSCRIPTION_ID
。 运行代码示例以初始化管理客户端。
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Resources;
ArmClient client = new ArmClient(new DefaultAzureCredential());
添加发件人用户名
预配 Azure 托管域资源时,MailFrom 地址默认为 donotreply@xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azurecomm.net
。 如果已配置自定义域(如 notification.azurecommtest.net
MailFrom 地址),则默认为 donotreply@notification.azurecommtest.net
。
用户名是 MailFrom 地址中使用的用户别名。 例如,MailFrom 地址 contosoNewsAlerts@notification.azurecommtest.net
中的用户名为 contosoNewsAlerts
. 可以添加额外的发件人用户名,还可以使用更用户友好的显示名称进行配置。 在我们的示例中,显示名称为 Contoso News Alerts
.
使用资源组名称、电子邮件服务名称和要向其添加此用户名的域名更新代码示例。 在门户中,可以通过导航到您在设置先决条件时创建的域资源中找到此信息。 资源的标题为 <your-email-service-name>/<your-domain-name>
。 可以在域资源概述的“概要”部分中找到资源组名称和订阅 ID。
若要添加多个发件人用户名,需要多次重复此代码示例。
string subscriptionId = "<your-subscription-id>";
string resourceGroupName = "<your-resource-group-name>";
string emailServiceName = "<your-email-service-name>";
string domainName = "<your-domain-name>";
ResourceIdentifier senderUsernameResourceId = SenderUsernameResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, emailServiceName, domainName, "contosoNewsAlerts");
SenderUsernameResource senderUsernameResource = client.GetSenderUsernameResource(senderUsernameResourceId);
SenderUsernameResourceData data = new SenderUsernameResourceData()
{
Username = "contosoNewsAlerts",
DisplayName = "Contoso News Alerts",
};
await senderUsernameResource.UpdateAsync(WaitUntil.Completed, data);
删除发件人用户名
若要删除发送方用户名,请调用 DeleteAsync
函数于 senderUsernameResource
。
await senderUsernameResource.DeleteAsync(WaitUntil.Completed);
后续步骤
相关文章
先决条件
- 拥有有效订阅的 Azure 帐户。 免费创建帐户。
- 用于预配域的 Azure 电子邮件通信服务资源已准备好。 开始创建电子邮件通信资源。
- 预配了 Azure 托管域 或 自定义域 ,并准备好发送电子邮件。
- 我们使用 服务主体进行身份验证。 将 Microsoft Entra ID 应用程序的客户端 ID、租户 ID 和客户端机密的值设置为以下环境变量:
AZURE_CLIENT_ID
、AZURE_TENANT_ID
和AZURE_CLIENT_SECRET
。
安装必需包
npm install @azure/arm-communication
npm install @azure/identity
初始化管理客户端
将示例代码中的字段替换为你的域和电子邮件资源所在的订阅的订阅 ID。 运行代码示例以初始化管理客户端。
const { CommunicationServiceManagementClient } = require("@azure/arm-communication");
const { DefaultAzureCredential } = require("@azure/identity");
const credential = new DefaultAzureCredential();
const subscriptionId = "<your-subscription-id>";
mgmtClient = new CommunicationServiceManagementClient(credential, subscriptionId);
添加发件人用户名
预配 Azure 托管域资源时,MailFrom 地址默认为 donotreply@xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azurecomm.net
。 如果已配置自定义域(如 notification.azurecommtest.net
MailFrom 地址),则默认为 donotreply@notification.azurecommtest.net
。
用户名是 MailFrom 地址中使用的用户别名。 例如,MailFrom 地址 contosoNewsAlerts@notification.azurecommtest.net
中的用户名为 contosoNewsAlerts
. 可以添加额外的发件人用户名,还可以使用更用户友好的显示名称进行配置。 在我们的示例中,显示名称为 Contoso News Alerts
.
使用资源组名称、电子邮件服务名称和要向其添加此用户名的域名更新代码示例。 在门户中,可以通过导航到您在设置先决条件时创建的域资源中找到此信息。 资源的标题为 <your-email-service-name>/<your-domain-name>
。 可以在域资源概述的“概要”部分中找到资源组名称。
若要添加多个发件人用户名,需要多次重复此代码示例。
const resourceGroupName = "<your-resource-group-name>";
const emailServiceName = "<your-email-service-name>";
const domainName = "<your-domain-name>";
const parameters = {
displayName: "Contoso News Alerts",
username: "contosoNewsAlerts",
};
await mgmtClient.senderUsernames.createOrUpdate(
resourceGroupName,
emailServiceName,
domainName,
"contosoNewsAlerts",
parameters
);
删除发件人用户名
若要删除发件人用户名,请调用客户端上的 delete 函数。
await mgmtClient.senderUsernames.delete(
resourceGroupName,
emailServiceName,
domainName,
"contosoNewsAlerts"
);
后续步骤
相关文章
先决条件
- 拥有有效订阅的 Azure 帐户。 免费创建帐户。
- 用于预配域的 Azure 电子邮件通信服务资源已准备好。 开始创建电子邮件通信资源。
- 预配了 Azure 托管域 或 自定义域 ,并准备好发送电子邮件。
- 我们使用 服务主体进行身份验证。 将 Microsoft Entra ID 应用程序的客户端 ID、租户 ID 和客户端机密的值设置为以下环境变量:
AZURE_CLIENT_ID
、AZURE_TENANT_ID
和AZURE_CLIENT_SECRET
。
安装必需包
将以下依赖项添加到 pom.xml
。
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-communication</artifactId>
<version>2.0.0</version>
</dependency>
初始化管理客户端
使用你的域和电子邮件资源所位于的订阅的订阅 ID 设置环境变量 AZURE_SUBSCRIPTION_ID
。 运行代码示例以初始化管理客户端。
AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
.build();
CommunicationManager manager = CommunicationManager
.authenticate(credential, profile);
添加发件人用户名
预配 Azure 托管域资源时,MailFrom 地址默认为 donotreply@xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azurecomm.net
。 如果已配置自定义域(如 notification.azurecommtest.net
MailFrom 地址),则默认为 donotreply@notification.azurecommtest.net
。
用户名是 MailFrom 地址中使用的用户别名。 例如,MailFrom 地址 contosoNewsAlerts@notification.azurecommtest.net
中的用户名为 contosoNewsAlerts
. 可以添加额外的发件人用户名,还可以使用更用户友好的显示名称进行配置。 在我们的示例中,显示名称为 Contoso News Alerts
.
使用资源组名称、电子邮件服务名称和要向其添加此用户名的域名更新代码示例。 在门户中,可以通过导航到您在设置先决条件时创建的域资源中找到此信息。 资源的标题为 <your-email-service-name>/<your-domain-name>
。 可以在域资源概述的“概要”部分中找到资源组名称。
若要添加多个发件人用户名,需要多次重复此代码示例。
String resourceGroupName = "<your-resource-group-name>";
String emailServiceName = "<your-email-service-name>";
String domainName = "<your-domain-name>";
manager
.senderUsernames()
.define("contosoNewsAlerts")
.withExistingDomain(resourceGroupName, emailServiceName, domainName)
.withUsername("contosoNewsAlerts")
.withDisplayName("Contoso News Alerts")
.create();
删除发件人用户名
若要删除发送方用户名,请调用 deleteWithResponse
客户端上的函数。
manager
.senderUsernames()
.deleteWithResponse(
resourceGroupName,
emailServiceName,
domainName,
"contosoNewsAlerts",
com.azure.core.util.Context.NONE);
后续步骤
相关文章
先决条件
- 拥有有效订阅的 Azure 帐户。 免费创建帐户。
- 用于预配域的 Azure 电子邮件通信服务资源已准备好。 开始创建电子邮件通信资源。
- 预配了 Azure 托管域 或 自定义域 ,并准备好发送电子邮件。
- 我们使用 服务主体进行身份验证。 将 Microsoft Entra ID 应用程序的客户端 ID、租户 ID 和客户端机密的值设置为以下环境变量:
AZURE_CLIENT_ID
、AZURE_TENANT_ID
和AZURE_CLIENT_SECRET
。
安装必需包
pip install azure-mgmt-communication
pip install azure-identity
初始化管理客户端
将示例代码中的字段替换为你的域和电子邮件资源所在的订阅的订阅 ID。 运行代码示例以初始化管理客户端。
from azure.mgmt.communication import CommunicationServiceManagementClient
from azure.identity import AzureCliCredential
credential = DefaultAzureCredential()
subscription_id = "<your-subscription-id>"
mgmt_client = CommunicationServiceManagementClient(credential, subscription_id)
添加发件人用户名
预配 Azure 托管域资源时,MailFrom 地址默认为 donotreply@xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azurecomm.net
。 如果已配置自定义域(如 notification.azurecommtest.net
MailFrom 地址),则默认为 donotreply@notification.azurecommtest.net
。
用户名是 MailFrom 地址中使用的用户别名。 例如,MailFrom 地址 contosoNewsAlerts@notification.azurecommtest.net
中的用户名为 contosoNewsAlerts
. 可以添加额外的发件人用户名,还可以使用更用户友好的显示名称进行配置。 在我们的示例中,显示名称为 Contoso News Alerts
.
使用资源组名称、电子邮件服务名称和要向其添加此用户名的域名更新代码示例。 可以通过导航到设置先决条件时创建的域资源,在门户中找到此信息。 资源的标题为 <your-email-service-name>/<your-domain-name>
。 可以在域资源概述的 “概要” 部分中找到资源组名称。
若要添加多个发件人用户名,需要多次重复此代码示例。
resource_group_name = "<your-resource-group-name>"
email_service_name = "<your-email-service-name>"
domain_name = "<your-domain-name>"
parameters = {
"username": "contosoNewsAlerts",
"displayName": "Contoso News Alerts",
}
mgmt_client.sender_usernames.create_or_update(
resource_group_name,
email_service_name,
domain_name,
"contosoNewsAlerts",
parameters
)
删除发件人用户名
若要删除发件人用户名,请调用客户端上的 delete 函数。
mgmt_client.sender_usernames.delete(
resource_group_name,
email_service_name,
domain_name,
"contosoNewsAlerts"
)