|
| 1 | +--- |
| 2 | +title: include file |
| 3 | +description: include file |
| 4 | +author: Deepika0530 |
| 5 | +manager: koagbakp |
| 6 | +services: azure-communication-services |
| 7 | +ms.author: v-deepikal |
| 8 | +ms.date: 17/02/2025 |
| 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 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 | +>[!NOTE] |
| 46 | +> Don't store your connection string as an unencrypted environment variable for production environments. This is meant for testing purposes only. For production environments, you should generate new connection strings. We encourage you to encrypt connection strings and change them regularly. |
| 47 | +
|
| 48 | +##### [Windows](#tab/windows) |
| 49 | + |
| 50 | +```console |
| 51 | +setx AZURE_COMMUNICATION_CONNECTION_STRING "<yourConnectionString>" |
| 52 | +``` |
| 53 | + |
| 54 | +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. |
| 55 | + |
| 56 | +##### [macOS](#tab/unix) |
| 57 | + |
| 58 | +Edit your **`.zshrc`**, and add the environment variable: |
| 59 | + |
| 60 | +```bash |
| 61 | +export AZURE_COMMUNICATION_CONNECTION_STRING="<connectionString>" |
| 62 | +``` |
| 63 | + |
| 64 | +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. |
| 65 | + |
| 66 | +##### [Linux](#tab/linux) |
| 67 | + |
| 68 | +Edit your **`.bash_profile`**, and add the environment variable: |
| 69 | + |
| 70 | +```bash |
| 71 | +export AZURE_COMMUNICATION_CONNECTION_STRING="<connectionString>" |
| 72 | +``` |
| 73 | + |
| 74 | +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. |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +## Send an email message with inline attachment |
| 79 | + |
| 80 | +```azurecli-interactive |
| 81 | +az communication email send |
| 82 | + --connection-string "yourConnectionString" |
| 83 | + |
| 84 | + |
| 85 | + --subject "Welcome to Azure Communication Services Email" |
| 86 | + --attachment-types "<inlineattachmenttype1>" # MIME type of the content being attached. Example: "png" |
| 87 | + --inline-attachments "<filepath>/<contentid>" # Example: "MicrosoftLogo.png/MSLogo" |
| 88 | + --html "<html><head><title>Welcome to Azure Communication Services Email</title></head><body><h1>This email message is sent from Azure Communication Services Email using Azure CLI.</h1><img src='cid:<contentid>' alt='<alternatetext>'/></body></html>" |
| 89 | +``` |
| 90 | +Make these replacements in the code: |
| 91 | + |
| 92 | +- Replace `<yourConnectionString>` with your connection string. |
| 93 | +- Replace `<[email protected]>` with the email address you would like to send a message to. |
| 94 | +- Replace `<[email protected]>` with the MailFrom address of your verified domain. |
| 95 | +- Replace `<inlineattachmenttype1>` with the actual attachment type of the file. |
| 96 | +- Replace `<filepath>/<contentid>` with the file path to your attachment and the cid name or id for your inline attachment. |
| 97 | +- Replace `<contentid>` with the CID for your inline attachment, which is referred to in the img src part of the HTML. |
| 98 | +- Replace `<alternatetext>` with a descriptive text for the image to help with accessibility. |
| 99 | + |
| 100 | +## Send an email message with attachment and inline attachment |
| 101 | + |
| 102 | +```azurecli-interactive |
| 103 | +az communication email send |
| 104 | + --connection-string "yourConnectionString" |
| 105 | + |
| 106 | + |
| 107 | + --subject "Welcome to Azure Communication Services Email" |
| 108 | + --attachment-types "<attachmenttype1>" "<inlineattachmenttype1>" # MIME type of the content being attached. Example1: "jpg" "png" & Example2: "png" "png" |
| 109 | + --attachments "<filepath>" # Example: "MSLogo.jpg" |
| 110 | + --inline-attachments "<filepath>/<contentid>" # Example: "MicrosoftLogo.png/MSLogo" |
| 111 | + --html "<html><head><title>Welcome to Azure Communication Services Email</title></head><body><h1>This email message is sent from Azure Communication Services Email using Azure CLI.</h1><img src='cid:<contentid>' alt='<alternatetext>'/></body></html>" |
| 112 | +``` |
| 113 | + |
| 114 | +Make these replacements in the code: |
| 115 | + |
| 116 | +- Replace `<yourConnectionString>` with your connection string. |
| 117 | +- Replace `<[email protected]>` with the email address you would like to send a message to. |
| 118 | +- Replace `<[email protected]>` with the MailFrom address of your verified domain. |
| 119 | +- Replace `<attachmenttype1>` `<inlineattachmenttype1>` with the actual attachment type of the file. |
| 120 | +- Replace `<filepath>` with the file path to your attachment. |
| 121 | +- Replace `<filepath>/<contentid>` with the file path to your attachment and the cid name or id for your inline attachment. |
| 122 | +- Replace `<contentid>` with the CID for your inline attachment, which is referred to in the img src part of the HTML. |
| 123 | +- Replace `<alternatetext>` with a descriptive text for the image to help with accessibility. |
| 124 | + |
| 125 | +## Send an email message with multiple attachments and inline attachments |
| 126 | + |
| 127 | +```azurecli-interactive |
| 128 | +az communication email send |
| 129 | + --connection-string "yourConnectionString" |
| 130 | + |
| 131 | + |
| 132 | + --subject "Welcome to Azure Communication Services Email" |
| 133 | + --attachment-types "<attachmenttype1>" "<attachmenttype2>" "<inlineattachmenttype1>" "<inlineattachmenttype2>" "<inlineattachmenttype3>" # MIME type of the content being attached. Example: "png" "jpg" "png" "jpg" "bmp" |
| 134 | + --attachments "<filepath1>" "<filepath2>" |
| 135 | + --inline-attachments "<filepath1>/<contentid1>" "<filepath2>/<contentid2>" "<filepath3>/<contentid3>" |
| 136 | + --html "<html><head><title>Welcome to Azure Communication Services Email</title></head><body><h1>This email message is sent from Azure Communication Services Email using Azure CLI.</h1><img src='cid:<contentid1>' alt='<alternatetext>'/><img src='cid:<contentid2>' alt='<alternatetext>'/><img src='cid:<contentid3>' alt='<alternatetext>'/></body></html>" |
| 137 | +``` |
| 138 | + |
| 139 | +Make these replacements in the code: |
| 140 | + |
| 141 | +- Replace `<yourConnectionString>` with your connection string. |
| 142 | +- Replace `<[email protected]>` with the email address you would like to send a message to. |
| 143 | +- Replace `<[email protected]>` with the MailFrom address of your verified domain. |
| 144 | +- Replace `<attachmenttype1>` `<attachmenttype2>` `<inlineattachmenttype1>` `<inlineattachmenttype2>` `<inlineattachmenttype3>` with the actual attachment types of the file. |
| 145 | +- Replace `<filepath1>` `<filepath2>` with the file paths to your attachment. |
| 146 | +- Replace `<filepath1>/<contentid1>` `<filepath2>/<contentid2>` `<filepath3>/<contentid3>` with the file paths to your attachment and the cid name or id for your inline attachment. |
| 147 | +- Replace `<contentid1>` `<contentid2>` `<contentid3>` with the CID for your inline attachment, which is referred to in the img src part of the HTML. |
| 148 | +- Replace `<alternatetext>` with a descriptive text for the image to help with accessibility. |
| 149 | + |
| 150 | +The above command also performs a polling on the messageId and returns the status of the email delivery. The status can be one of the following: |
| 151 | + |
| 152 | +[!INCLUDE [Email Message Status](../../includes/email-operation-status.md)] |
| 153 | + |
| 154 | +### Optional parameters |
| 155 | + |
| 156 | +The following optional parameters are available in Azure CLI. |
| 157 | + |
| 158 | +- `--html` can be used instead of `--text` for html email body. |
| 159 | + |
| 160 | +- `--importance` sets the importance type for the email. Known values are: high, normal, and low. Default is normal. |
| 161 | + |
| 162 | +- `--to` sets the list of email recipients. |
| 163 | + |
| 164 | +- `--cc` sets carbon copy email addresses. |
| 165 | + |
| 166 | +- `--bcc` sets blind carbon copy email addresses. |
| 167 | + |
| 168 | +- `--reply-to` sets Reply-To email address. |
| 169 | + |
| 170 | +- `--disable-tracking` indicates whether user engagement tracking should be disabled for this request. |
| 171 | + |
| 172 | +- `--attachments` sets the list of email attachments. |
| 173 | + |
| 174 | +>[!NOTE] |
| 175 | +> Please note that we limit the total size of an email request (which includes both regular and inline attachments) to 10MB. |
| 176 | +
|
| 177 | +- `--attachment-types` sets the list of email attachment types, in the same order of attachments. |
| 178 | + |
| 179 | +- `--inline-attachments` parameter embeds an attachment directly within the email body, instead of as a separate downloadable file. It's commonly used for images or media files that should appear inline in the email content. |
| 180 | + |
| 181 | +>[!NOTE] |
| 182 | +> There needs to be at least one recipient in `--to` or `--cc` or `--bcc`. |
| 183 | + |
0 commit comments