|
| 1 | +--- |
| 2 | +title: How to create authentication credentials for sending emails using SMTP |
| 3 | +titleSuffix: An Azure Communication Services Quickstart |
| 4 | +description: Learn about how to use a service principal to create authentication credentials for sending emails using SMTP. |
| 5 | +author: ddouglas-msft |
| 6 | +services: azure-communication-services |
| 7 | +ms.author: ddouglas |
| 8 | +ms.date: 10/18/2023 |
| 9 | +ms.topic: quickstart |
| 10 | +ms.service: azure-communication-services |
| 11 | +zone_pivot_groups: acs-smtp-role-assignment |
| 12 | +--- |
| 13 | + |
| 14 | +# Assign a role to a Microsoft Entra application for SMTP authentication |
| 15 | + |
| 16 | +This article describes how to use a Microsoft Entra application to create the authentication credentials for using Simple Mail Transfer Protocol (SMTP) to send an email using Azure Communication Services. |
| 17 | + |
| 18 | +## Prerequisites |
| 19 | + |
| 20 | +- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F). |
| 21 | +- An Azure Communication Email Resource created and ready with a provisioned domain [Get started with Creating Email Communication Resource](../create-email-communication-resource.md) |
| 22 | +- An active Azure Communication Services Resource connected with Email Domain and a Connection String. [Get started by Connecting Email Resource with a Communication Resource](../connect-email-communication-resource.md) |
| 23 | +- A Microsoft Entra application with access to the Azure Communication Services Resource. [Register an application with Microsoft Entra ID and create a service principal](/entra/identity-platform/howto-create-service-principal-portal#register-an-application-with-microsoft-entra-id-and-create-a-service-principal) |
| 24 | +- A client secret for the Microsoft Entra application with access to the Azure Communication Service Resource. [Create a new client secret](/entra/identity-platform/howto-create-service-principal-portal#option-3-create-a-new-client-secret) |
| 25 | + |
| 26 | +## Use a Microsoft Entra application for SMTP authentication |
| 27 | + |
| 28 | +Application developers who build apps that send email using the SMTP protocol need to implement secure, modern authentication. Azure Communication Services uses Microsoft Entra application service principals to provide secure authentication. Link a Microsoft Entra application to the Communication Service resource by creating an SMTP Username resource. |
| 29 | + |
| 30 | +The SMTP services uses the Microsoft Entra application information linked to the SMTP username to authenticate with Microsoft Entra on the user's behalf to ensure a secure and seamless email transmission. SMTP Username resources are user-defined and can use either email format or freeform. If an SMTP username uses the email format, the domain must be one of the Communication Service resource's linked domains. |
| 31 | + |
| 32 | +You also need to give the Microsoft Entra application access to the Communication resource using either a built-in role or a custom role with the required permissions. |
| 33 | + |
| 34 | +#### [Built-in role](#tab/built-in-role) |
| 35 | +## Assign the built-in Communication and Email Service Owner role to the Microsoft Entra application |
| 36 | +Assign the **Communication and Email Service Owner** role to a Microsoft Entra application to give it access to a Communication Service resource. |
| 37 | + |
| 38 | +1. In the portal, navigate to the Azure Communication Service Resource used to send emails using SMTP and then open **Access control (IAM)**. |
| 39 | + :::image type="content" source="../media/smtp-custom-role-iam.png" alt-text="Screenshot that shows Access control for the Communication resource."::: |
| 40 | +1. Click **+Add** and then select **Add role assignment**. |
| 41 | + :::image type="content" source="../media/email-smtp-add-role-assignment.png" alt-text="Screenshot that shows selecting Add role assignment for the Communication resource."::: |
| 42 | +1. On the **Role** tab, select the **Communication and Email Service Owner** role for sending emails using SMTP and click **Next**. |
| 43 | + :::image type="content" source="../media/email-smtp-builtin-select-role.png" alt-text="Screenshot that shows selecting the built-in role."::: |
| 44 | +1. On the **Members** tab, choose **User, group, or service principal** and then click **+Select members**. |
| 45 | + :::image type="content" source="../media/email-smtp-builtin-select-members.png" alt-text="Screenshot that shows choosing select members for the built-in role."::: |
| 46 | +1. Use the search box to find the **Microsoft Entra** application that you'll use for authentication and select it. Then click **Select**. |
| 47 | + :::image type="content" source="../media/email-smtp-builtin-select-entra.png" alt-text="Screenshot that shows selecting the Microsoft Entra application that will get the built-in role."::: |
| 48 | +1. After confirming the selection, click **Next**. |
| 49 | + :::image type="content" source="../media/email-smtp-builtin-select-review.png" alt-text="Screenshot that shows reviewing the assignment for the built-in role."::: |
| 50 | +1. After confirming the scope and members, click **Review + assign**. |
| 51 | + :::image type="content" source="../media/email-smtp-builtin-select-assign.png" alt-text="Screenshot that shows assigning the built-in role."::: |
| 52 | + |
| 53 | +#### [Custom role](#tab/custom-role) |
| 54 | +## Use a custom role to limit permissions granted to the Microsoft Entra Application |
| 55 | + |
| 56 | +The **Communication and Email Service Owner** role gives access to all Communication and Email service operations. You can create a custom role to limit access to only the operations needed to send emails using SMTP. Assign the Microsoft Entra application a role with both the **Microsoft.Communication/CommunicationServices/Read**, **Microsoft.Communication/CommunicationServices/Write**, and the **Microsoft.Communication/EmailServices/write** permissions on the Azure Communication Service Resource. |
| 57 | + |
| 58 | +### Create a custom email role for the Microsoft Entra application |
| 59 | +1. In the portal, create a custom role by first navigating to the subscription, resource group, or Azure Communication Service Resource where you want the custom role to be assignable and then open **Access control (IAM)**. |
| 60 | + :::image type="content" source="../media/smtp-custom-role-iam.png" alt-text="Screenshot that shows Access control."::: |
| 61 | +1. Click the **Roles** tab to see a list of all the built-in and custom roles. |
| 62 | +1. Search for a role you want to clone such as the Reader role. |
| 63 | +1. At the end of the row, click the ellipsis (...) and then click **Clone**. |
| 64 | + :::image type="content" source="../media/smtp-custom-role-clone.png" alt-text="Screenshot that shows cloning a role."::: |
| 65 | +1. Click the **Basics** tab and give a name to the new role. |
| 66 | + :::image type="content" source="../media/smtp-custom-role-basics.png" alt-text="Screenshot that shows creating a name for a new custom role."::: |
| 67 | +1. Click the **Permissions** tab and click **Add permissions**. |
| 68 | + :::image type="content" source="../media/smtp-custom-role-addpermissions.png" alt-text="Screenshot that shows how to add permissions to custom role."::: |
| 69 | +1. Search for **Microsoft.Communication** and select **Azure Communication Services** |
| 70 | + :::image type="content" source="../media/smtp-custom-role-permissions.png" alt-text="Screenshot that shows adding permissions for a new custom role."::: |
| 71 | +1. Select the **Microsoft.Communication/CommunicationServices** **Read**, **Microsoft.Communication/CommunicationServices** **Write**, and the **Microsoft.Communication/EmailServices** **Write** permissions. Click **Add**. |
| 72 | + :::image type="content" source="../media/smtp-custom-role-add-permissions.png" alt-text="Screenshot that shows adding Azure Communication Services' permissions."::: |
| 73 | +1. Review the permissions for the new role. Click **Review + create** and then **Create** on the next page. |
| 74 | + :::image type="content" source="../media/smtp-custom-role-review.png" alt-text="Screenshot that shows reviewing the new custom role."::: |
| 75 | + |
| 76 | +When assigning the Microsoft Entra application a role for the Azure Communication Services Resource, the new custom role will be available. For more information on creating custom roles, see [Create or update Azure custom roles using the Azure portal](../../../../role-based-access-control/custom-roles-portal.md) |
| 77 | + |
| 78 | +### Assign the custom email role to the Microsoft Entra application |
| 79 | +1. In the portal, navigate to the subscription, resource group, or Azure Communication Service Resource where you want the custom role to be assignable and then open **Access control (IAM)**. |
| 80 | + :::image type="content" source="../media/smtp-custom-role-iam.png" alt-text="Screenshot that shows Access control."::: |
| 81 | +1. Click **+Add** and then select **Add role assignment**. |
| 82 | + :::image type="content" source="../media/email-smtp-add-role-assignment.png" alt-text="Screenshot that shows selecting Add role assignment."::: |
| 83 | +1. On the **Role** tab, select the custom role created for sending emails using SMTP and click **Next**. |
| 84 | + :::image type="content" source="../media/email-smtp-select-custom-role.png" alt-text="Screenshot that shows selecting the custom role."::: |
| 85 | +1. On the **Members** tab, choose **User, group, or service principal** and then click **+Select members**. |
| 86 | + :::image type="content" source="../media/email-smtp-select-members.png" alt-text="Screenshot that shows choosing select members."::: |
| 87 | +1. Use the search box to find the **Microsoft Entra** application that you'll use for authentication and select it. Then click **Select**. |
| 88 | + :::image type="content" source="../media/email-smtp-select-entra.png" alt-text="Screenshot that shows selecting the Microsoft Entra application."::: |
| 89 | +1. After confirming the selection, click **Next**. |
| 90 | + :::image type="content" source="../media/email-smtp-select-review.png" alt-text="Screenshot that shows reviewing the assignment."::: |
| 91 | +1. After confirming the scope and members, click **Review + assign**. |
| 92 | + :::image type="content" source="../media/email-smtp-select-assign.png" alt-text="Screenshot that shows assigning the custom role."::: |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +## Create an SMTP Username using the Azure Portal |
| 97 | +1. In the portal, navigate to the Azure Communication Service Resource and then open **SMTP Usernames**. |
| 98 | + :::image type="content" source="../media/smtpusernames-1-usernameblade.png" alt-text="Screenshot that shows SMTP Usernames."::: |
| 99 | +1. Click **+Add* SMTP Username* and then select the Microsoft Entra application. If the Microsoft Entra application does not appear in the drop-down, see the previous steps to assign a role. The username can be custom text or an email address. |
| 100 | + :::image type="content" source="../media/smtpusernames-2-addsmtpusername.png" alt-text="Screenshot that shows adding an SMTP username."::: |
| 101 | +1. Verify the SMTP Username is in the list. The status changes to **Ready to use** once all of the requirements for sending an email using the username and SMTP are met. |
| 102 | + :::image type="content" source="../media/smtpusernames-3-list.png" alt-text="Screenshot that shows newly created SMTP username in the list."::: |
| 103 | + |
| 104 | +## SMTP authentication password |
| 105 | +The password is one of the Microsoft Entra application's client secrets. |
| 106 | + :::image type="content" source="../media/email-smtp-entra-secret.png" alt-text="Screenshot that shows finding the Microsoft Entra client secret."::: |
| 107 | + |
| 108 | +## Requirements for SMTP AUTH client submission |
| 109 | + |
| 110 | +- **Authentication**: Username and password authentication is supported using an SMTP username linked to a Microsoft Entra application details. The Azure Communication Services SMTP service use the Microsoft Entra application details to get an access token on behalf of the user and use that to submit the email. |
| 111 | +- **Azure Communication Service**: An Azure Communication Services Resource with a connected Azure Communication Email Resource and domain is required. |
| 112 | +- **Transport Layer Security (TLS)**: Your device must be able to use TLS version 1.2 and above. |
| 113 | +- **Port**: Port 587 (recommended) or port 25 is required and must be unblocked on your network. Some network firewalls or ISPs block ports because that's the port that email servers use to send mail. |
| 114 | +- **DNS**: Use the DNS name smtp.azurecomm.net. Don't use an IP address for the Microsoft 365 or Office 365 server, as IP Addresses aren't supported. |
| 115 | + |
| 116 | +## How to set up SMTP AUTH client submission |
| 117 | + |
| 118 | +Enter the following settings directly on your device or in the application as their guide instructs (it might use different terminology than this article). Provided your scenario aligns with the prerequisites for SMTP AUTH client submission, these settings enable you to send emails from your device or application using SMTP Commands. |
| 119 | + |
| 120 | +| Device or Application setting | Value | |
| 121 | +|--|--| |
| 122 | +|Server / smart host | smtp.azurecomm.net | |
| 123 | +|Port |Port 587 (recommended) or port 25| |
| 124 | +|TLS / StartTLS | Enabled| |
| 125 | +|Username and password | Enter the SMTP Username and one Microsoft Entra application's client secrets. | |
0 commit comments