Quickstart: How to add and remove sender addresses in Azure Communication Services using the Azure Communication Services Management Client Libraries

In this quick start, you will learn how to add and remove sender addresses in Azure Communication Services using the Azure Communication Services Management Client Libraries.

Prerequisites

Install the required packages

dotnet add package Azure.ResourceManager.Communication

Initialize the management client

Set the environment variable AZURE_SUBSCRIPTION_ID with the subscription id of the subscription your Domain and Email resources are in. Run the code sample to initialize the management client.

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());

Add sender usernames

When an Azure Managed Domain resource is provisioned, the MailFrom address defaults to donotreply@xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azurecomm.net. If you have configured a custom domain such as "notification.azurecommtest.net" the MailFrom address defaults to "donotreply@notification.azurecommtest.net".

The username is the user alias that is used in the MailFrom address. For example, the username in the MailFrom address contosoNewsAlerts@notification.azurecommtest.net would be contosoNewsAlerts. You can add extra sender usernames, which can also be configured with a more user friendly display name. In our example, the display name is Contoso News Alerts.

Update the code sample with the resource group name, the email service name, and the domain name that you would like to add this username to. This information can be found in portal by navigating to the domains resource you created when setting up the prerequisites. The title of the resource is <your-email-service-name>/<your-domain-name>. The resource group name and subscription ID can be found in the Essentials sections in the domain resource overview.

To add multiple sender usernames, you need to repeat this code sample multiple times.

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);

Remove sender usernames

To delete the sender username, call the DeleteAsync function on the senderUsernameResource.

await senderUsernameResource.DeleteAsync(WaitUntil.Completed);

Next steps

The following documents may interest you:

Prerequisites

Install the required packages

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

Initialize the management client

Replace the field in the sample code with the subscription ID of the subscription your Domain and Email resources are in. Run the code sample to initialize the management client.

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);

Add sender usernames

When an Azure Managed Domain resource is provisioned, the MailFrom address defaults to donotreply@xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azurecomm.net. If you have configured a custom domain such as "notification.azurecommtest.net" the MailFrom address defaults to "donotreply@notification.azurecommtest.net".

The username is the user alias that is used in the MailFrom address. For example, the username in the MailFrom address contosoNewsAlerts@notification.azurecommtest.net would be contosoNewsAlerts. You can add extra sender usernames, which can also be configured with a more user friendly display name. In our example, the display name is Contoso News Alerts.

Update the code sample with the resource group name, the email service name, and the domain name that you would like to add this username to. This information can be found in portal by navigating to the domains resource you created when setting up the prerequisites. The title of the resource is <your-email-service-name>/<your-domain-name>. The resource group name can be found in the Essentials sections in the domain resource overview.

To add multiple sender usernames, you need to repeat this code sample multiple times.

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
);

Remove sender usernames

To delete the sender username, call the delete function on the client.

await mgmtClient.senderUsernames.delete(
    resourceGroupName,
    emailServiceName,
    domainName,
    "contosoNewsAlerts"
);

Next steps

The following documents may interest you:

Prerequisites

Install the required packages

Add the following dependency to your pom.xml.

<dependency>
    <groupId>com.azure.resourcemanager</groupId>
    <artifactId>azure-resourcemanager-communication</artifactId>
    <version>2.0.0</version>
</dependency>

Initialize the management client

Set the environment variable AZURE_SUBSCRIPTION_ID with the subscription ID of the subscription your Domain and Email resources are in. Run the code sample to initialize the management client.

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

Add sender usernames

When an Azure Managed Domain resource is provisioned, the MailFrom address defaults to donotreply@xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azurecomm.net. If you have configured a custom domain such as "notification.azurecommtest.net" the MailFrom address defaults to "donotreply@notification.azurecommtest.net".

The username is the user alias that is used in the MailFrom address. For example, the username in the MailFrom address contosoNewsAlerts@notification.azurecommtest.net would be contosoNewsAlerts. You can add extra sender usernames, which can also be configured with a more user friendly display name. In our example, the display name is Contoso News Alerts.

Update the code sample with the resource group name, the email service name, and the domain name that you would like to add this username to. This information can be found in portal by navigating to the domains resource you created when setting up the prerequisites. The title of the resource is <your-email-service-name>/<your-domain-name>. The resource group name can be found in the Essentials sections in the domain resource overview.

To add multiple sender usernames, you need to repeat this code sample multiple times.

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();

Remove sender usernames

To delete the sender username, call the deleteWithResponse function on the client.

manager
    .senderUsernames()
    .deleteWithResponse(
        resourceGroupName,
        emailServiceName,
        domainName,
        "contosoNewsAlerts",
        com.azure.core.util.Context.NONE);

Next steps

The following documents may interest you:

Prerequisites

Install the required packages

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

Initialize the management client

Replace the field in the sample code with the subscription ID of the subscription your Domain and Email resources are in. Run the code sample to initialize the management client.

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

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

mgmt_client = CommunicationServiceManagementClient(credential, subscription_id)

Add sender usernames

When an Azure Managed Domain resource is provisioned, the MailFrom address defaults to donotreply@xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azurecomm.net. If you have configured a custom domain such as "notification.azurecommtest.net" the MailFrom address defaults to "donotreply@notification.azurecommtest.net".

The username is the user alias that is used in the MailFrom address. For example, the username in the MailFrom address contosoNewsAlerts@notification.azurecommtest.net would be contosoNewsAlerts. You can add extra sender usernames, which can also be configured with a more user friendly display name. In our example, the display name is Contoso News Alerts.

Update the code sample with the resource group name, the email service name, and the domain name that you would like to add this username to. This information can be found in portal by navigating to the domains resource you created when setting up the prerequisites. The title of the resource is <your-email-service-name>/<your-domain-name>. The resource group name can be found in the Essentials sections in the domain resource overview.

To add multiple sender usernames, you need to repeat this code sample multiple times.

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
)

Remove sender usernames

To delete the sender username, call the delete function on the client.

mgmt_client.sender_usernames.delete(
    resource_group_name,
    email_service_name,
    domain_name,
    "contosoNewsAlerts"
)

Next steps

The following documents may interest you: