Search code examples
c#azure-communication-services

How to add and remove Multiple Sender Addresses to Azure Email Communication Service programmatically


We can add multiple email sender's addresses after configuring custom domain (https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/email/add-multiple-senders):

adding sender

Now, I want to do it programmatically with some of the SDKs. Is there any possibilities to do that?


Solution

  • I found examples here: https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/email/add-multiple-senders-mgmt-sdks?pivots=programming-language-csharp

    string subscriptionId = "";
    string resourceGroupName = "";
    string emailServiceName = "";
    string domainName = "";
    string emailAddressToAdd = "no-replay";
    ArmClient client = new(new DefaultAzureCredential());
    
    ResourceIdentifier senderUsernameResourceId = SenderUsernameResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, emailServiceName, domainName, emailAddressToAdd);
    SenderUsernameResource senderUsernameResource = client.GetSenderUsernameResource(senderUsernameResourceId);
    
    SenderUsernameResourceData data = new()
    {
        Username = emailAddressToAdd,
        DisplayName = "No Replay",
    };
    senderUsernameResource.Update(WaitUntil.Completed, data);