|
| 1 | +--- |
| 2 | +title: include file |
| 3 | +description: include file |
| 4 | +author: mayssamm |
| 5 | +manager: ankita |
| 6 | +services: azure-communication-services |
| 7 | +ms.author: mayssamm |
| 8 | +ms.date: 02/03/2023 |
| 9 | +ms.topic: include |
| 10 | +ms.service: azure-communication-services |
| 11 | +ms.custom: include files |
| 12 | +--- |
| 13 | + |
| 14 | +Get started with Azure Communication Services by using the Azure CLI communication extension to send Email messages. |
| 15 | + |
| 16 | +Completing this quick start incurs a small cost of a few USD cents or less in your Azure account. |
| 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 Email Communication Services resource created and ready with a provisioned domain. [Get started with creating an Email Communication Resource](../create-email-communication-resource.md). |
| 22 | +- An active Azure Communication Services resource connected to an Email Domain and its connection string. [Get started by connecting an Email Communication Resource with a Azure Communication Resource](../connect-email-communication-resource.md). |
| 23 | +- The latest [Azure CLI](/cli/azure/install-azure-cli-windows?tabs=azure-cli). |
| 24 | + |
| 25 | +### Prerequisite check |
| 26 | +- In a terminal or command window, run the `az --version` command to check that Azure CLI and the communication extension are installed. |
| 27 | +- To view the domains verified with your Email Communication Services resource, sign in to the [Azure portal](https://portal.azure.com/). Locate your Email Communication Services resource and open the **Provision domains** tab from the left navigation pane. |
| 28 | + |
| 29 | +## Setting up |
| 30 | +### Add the extension |
| 31 | +Add the Azure Communication Services extension for Azure CLI by using the `az extension` command. |
| 32 | + |
| 33 | +```azurecli-interactive |
| 34 | +az extension add --name communication |
| 35 | +``` |
| 36 | + |
| 37 | +### Sign in to Azure CLI |
| 38 | +You'll need to [sign in to Azure CLI](/cli/azure/authenticate-azure-cli). You can sign in running the ```az login``` command from the terminal and providing your credentials. |
| 39 | + |
| 40 | + |
| 41 | +### Store your connection string in an environment variable |
| 42 | + |
| 43 | +You can configure the `AZURE_COMMUNICATION_CONNECTION_STRING` environment variable to use Azure CLI keys operations without having to use `--connection_string` to pass in the connection string. To configure an environment variable, open a console window and select your operating system from the below tabs. Replace `<connectionString>` with your actual connection string. |
| 44 | + |
| 45 | +##### [Windows](#tab/windows) |
| 46 | + |
| 47 | +```console |
| 48 | +setx AZURE_COMMUNICATION_STRING "<yourConnectionString>" |
| 49 | +``` |
| 50 | + |
| 51 | +After you add the environment variable, you may need to restart any running programs that will need to read the environment variable, including the console window. For example, if you're using Visual Studio as your editor, restart Visual Studio before running the example. |
| 52 | + |
| 53 | +##### [macOS](#tab/unix) |
| 54 | + |
| 55 | +Edit your **`.zshrc`**, and add the environment variable: |
| 56 | + |
| 57 | +```bash |
| 58 | +export AZURE_COMMUNICATION_STRING="<connectionString>" |
| 59 | +``` |
| 60 | + |
| 61 | +After you add the environment variable, run `source ~/.zshrc` from your console window to make the changes effective. If you created the environment variable with your IDE open, you may need to close and reopen the editor, IDE, or shell in order to access the variable. |
| 62 | + |
| 63 | +##### [Linux](#tab/linux) |
| 64 | + |
| 65 | +Edit your **`.bash_profile`**, and add the environment variable: |
| 66 | + |
| 67 | +```bash |
| 68 | +export AZURE_COMMUNICATION_STRING="<connectionString>" |
| 69 | +``` |
| 70 | + |
| 71 | +After you add the environment variable, run `source ~/.bash_profile` from your console window to make the changes effective. If you created the environment variable with your IDE open, you may need to close and reopen the editor, IDE, or shell in order to access the variable. |
| 72 | + |
| 73 | +--- |
| 74 | + |
| 75 | +## Send an email message |
| 76 | + |
| 77 | +```azurecli-interactive |
| 78 | +az communication email send |
| 79 | + --connection-string "yourConnectionString" |
| 80 | + |
| 81 | + |
| 82 | + --subject "Welcome to Azure Communication Services Email" --text "This email message is sent from Azure Communication Services Email using Azure CLI." |
| 83 | +``` |
| 84 | + |
| 85 | +Make these replacements in the code: |
| 86 | + |
| 87 | +- Replace `<yourConnectionString>` with your connection string. |
| 88 | +- Replace " <[email protected]>" with the email address you would like to send a message to. |
| 89 | +- Replace " <[email protected]>" with the MailFrom address of your verified domain. |
| 90 | + |
| 91 | +To track the status of the email delivery, you'll need the `messageId` from the response. |
| 92 | + |
| 93 | +### Optional parameters |
| 94 | + |
| 95 | +The following optional parameters are available in Azure CLI. |
| 96 | + |
| 97 | +- `--html` can be used instead of `--text` for html email body. |
| 98 | + |
| 99 | +- `--importance` sets the importance type for the email. Known values are: high, normal, and low. Default is normal. |
| 100 | + |
| 101 | +- `--cc` sets carbon copy email addresses. |
| 102 | + |
| 103 | +- `--bcc` sets blind carbon copy email addresses. |
| 104 | + |
| 105 | +- `--reply-to` sets Reply-To email address. |
| 106 | + |
| 107 | +- `--disable-tracking` indicates whether user engagement tracking should be disabled for this request. |
| 108 | + |
| 109 | +- `--attachments` sets the list of email attachments. |
| 110 | + |
| 111 | +- `--attachment-types` sets the list of email attachment types, in the same order of attachments. |
| 112 | + |
| 113 | +Also, you can use a list of recipients with `--to`, similar to `--cc` and `--bcc`. |
| 114 | + |
| 115 | + |
| 116 | +## Get the status of the email delivery |
| 117 | + |
| 118 | +We can keep checking the email delivery status until the status is `OutForDelivery`. |
| 119 | + |
| 120 | +```azurecli-interactive |
| 121 | +az communication email status get --message-id "\<messageId\>" |
| 122 | +``` |
| 123 | + |
| 124 | +- Replace "\<messageId\>" with the messageId from the response of the send request. |
| 125 | + |
| 126 | +[!INCLUDE [Email Message Status](./email-message-status.md)] |
| 127 | + |
0 commit comments