|
| 1 | +--- |
| 2 | +title: include file |
| 3 | +description: include file |
| 4 | +author: yogeshmo |
| 5 | +manager: koagbakp |
| 6 | +services: azure-communication-services |
| 7 | +ms.author: yogeshmo |
| 8 | +ms.date: 04/19/2023 |
| 9 | +ms.topic: include |
| 10 | +ms.service: azure-communication-services |
| 11 | +ms.custom: mode-other |
| 12 | +--- |
| 13 | + |
| 14 | +## Prerequisites |
| 15 | + |
| 16 | +- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/dotnet/). |
| 17 | +- An Azure Email Communication Services Resource ready to provision domains. [Get started creating an Email Communication Resource](../create-email-communication-resource.md). |
| 18 | +- An [Azure Managed Domain](../add-azure-managed-domains.md) or [Custom Domain](../add-custom-verified-domains.md) provisioned and ready to send emails. |
| 19 | +- We are using a [service principal for authentication](../../../../active-directory/develop/howto-create-service-principal-portal.md). Set the values of the client ID, tenant ID and client secret of the AAD application as the following environment variables: `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, and `AZURE_CLIENT_SECRET`. |
| 20 | + |
| 21 | +## Install the required packages |
| 22 | + |
| 23 | +```console |
| 24 | +dotnet add package Azure.ResourceManager.Communication |
| 25 | +``` |
| 26 | + |
| 27 | +## Initialize the management client |
| 28 | + |
| 29 | +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. |
| 30 | + |
| 31 | +```csharp |
| 32 | +using System; |
| 33 | +using System.Threading.Tasks; |
| 34 | +using Azure.Core; |
| 35 | +using Azure.Identity; |
| 36 | +using Azure.ResourceManager; |
| 37 | +using Azure.ResourceManager.Compute; |
| 38 | +using Azure.ResourceManager.Resources; |
| 39 | + |
| 40 | +ArmClient client = new ArmClient(new DefaultAzureCredential()); |
| 41 | +``` |
| 42 | + |
| 43 | +## Add sender usernames |
| 44 | + |
| 45 | +When an Azure Managed Domain resource is provisioned, the MailFrom address defaults to [email protected]. If you have configured a custom domain such as "notification.azurecommtest.net" the MailFrom address defaults to " [email protected]". |
| 46 | + |
| 47 | +The username is the user alias that is used in the MailFrom address. For example, the username in the MailFrom address `[email protected]` 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`. |
| 48 | + |
| 49 | +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. |
| 50 | + |
| 51 | +To add multiple sender usernames, you need to repeat this code sample multiple times. |
| 52 | + |
| 53 | +```csharp |
| 54 | +string subscriptionId = "<your-subscription-id>"; |
| 55 | +string resourceGroupName = "<your-resource-group-name>"; |
| 56 | +string emailServiceName = "<your-email-service-name>"; |
| 57 | +string domainName = "<your-domain-name>"; |
| 58 | + |
| 59 | +ResourceIdentifier senderUsernameResourceId = SenderUsernameResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, emailServiceName, domainName, "contosoNewsAlerts"); |
| 60 | +SenderUsernameResource senderUsernameResource = client.GetSenderUsernameResource(senderUsernameResourceId); |
| 61 | + |
| 62 | +SenderUsernameResourceData data = new SenderUsernameResourceData() |
| 63 | +{ |
| 64 | + Username = "contosoNewsAlerts", |
| 65 | + DisplayName = "Contoso News Alerts", |
| 66 | +}; |
| 67 | + |
| 68 | +await senderUsernameResource.UpdateAsync(WaitUntil.Completed, data); |
| 69 | +``` |
| 70 | + |
| 71 | +## Remove sender usernames |
| 72 | + |
| 73 | +To delete the sender username, call the DeleteAsync function on the senderUsernameResource. |
| 74 | + |
| 75 | +```python |
| 76 | +await senderUsernameResource.DeleteAsync(WaitUntil.Completed); |
| 77 | +``` |
| 78 | + |
| 79 | +## Next steps |
| 80 | + |
| 81 | +* [Get started with create and manage Email Communication Service in Azure Communication Service](../create-email-communication-resource.md) |
| 82 | + |
| 83 | +* [Get started by connecting Email Communication Service with a Azure Communication Service resource](../connect-email-communication-resource.md) |
| 84 | + |
| 85 | +The following documents may interest you: |
| 86 | + |
| 87 | +- Familiarize yourself with the [Email client library](../../../concepts/email/sdk-features.md) |
| 88 | +- How to send emails with custom verified domains?[Add custom domains](../add-custom-verified-domains.md) |
0 commit comments