Skip to content

Commit 03cfccf

Browse files
authored
Merge pull request #294792 from Deepika0530/send-email-inline-attachments-cli-ps
Added inline attachments documentation for AzureCLI and PowerShell
2 parents 7a172ab + 4218c55 commit 03cfccf

File tree

8 files changed

+378
-4
lines changed

8 files changed

+378
-4
lines changed
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
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+
--sender "<[email protected]>"
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+
--sender "<[email protected]>"
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+
--sender "<[email protected]>"
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+
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
---
2+
title: include file
3+
description: include file
4+
author: Deepika0530
5+
manager: komivi.agbakpem
6+
services: azure-communication-services
7+
ms.author: v-deepikal
8+
ms.date: 17/02/2024
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 PowerShell communication module 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 PowerShell](/powershell/azure/install-azps-windows).
24+
25+
### Prerequisite check
26+
- In a windows powershell, run the `Get-Module -ListAvailable -Name Az.Communication` command to check whether the communication module is installed or not.
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+
### Install communication module
31+
Install the Azure Communication Services module for Azure PowerShell by using the `Install-Module -Name Az.Communication` command.
32+
33+
```azurepowershell-interactive
34+
Install-Module -Name Az.Communication
35+
```
36+
After installing Communication module, run the `Get-Command -Module Az.Communication` command to get all the communication modules.
37+
38+
```azurepowershell-interactive
39+
Get-Command -Module Az.Communication
40+
```
41+
42+
## Send an email message with inline attachment
43+
44+
Queues an email message to be sent to one or more recipients with only required fields.
45+
46+
```azurepowershell-interactive
47+
$emailRecipientTo = @(
48+
@{
49+
Address = "<[email protected]>"
50+
DisplayName = "Email DisplayName"
51+
},
52+
@{
53+
Address = "<[email protected]>"
54+
DisplayName = "Email DisplayName"
55+
}
56+
)
57+
58+
$fileBytes = [System.IO.File]::ReadAllBytes("<image file path>")
59+
60+
$emailAttachment = @(
61+
@{
62+
ContentInBase64 = $fileBytes
63+
ContentType = "<image/png>"
64+
Name = "<inline-attachment.png>"
65+
contentId = "<contentId>"
66+
}
67+
)
68+
69+
$message = @{
70+
ContentSubject = "Test Email"
71+
RecipientTo = @($emailRecipientTo) # Array of email address objects
72+
SenderAddress = '<[email protected]>'
73+
Attachment = @($emailAttachment) # Array of attachments
74+
ContentHtml = "<html><head><title>Enter title</title></head><body><img src='cid:<contentId>' alt='Company Logo'/><h1>This is the first email from ACS - Azure PowerShell</h1></body></html>"
75+
ContentPlainText = "This is the first email from ACS - Azure PowerShell"
76+
}
77+
```
78+
79+
Make these replacements in the code:
80+
81+
- Replace `<yourEndpoint>` with your endpoint.
82+
- Replace `<[email protected]>` with the email address you would like to send a message to.
83+
- Replace `<[email protected]>` with the MailFrom address of your verified domain.
84+
- Replace `<image file path>` with the actual file paths of the attachments you want to send.
85+
- Replace `<image/png>` with the appropriate content types for your attachments.
86+
- Replace `<inline-attachment.png>` with the filenames of your attachments.
87+
- Replace `<contentId>` with the Content-ID for your inline attachment.
88+
89+
Queues an email message to be sent to one or more inline attachments.
90+
91+
```azurepowershell-interactive
92+
$emailRecipientTo = @(
93+
@{
94+
Address = "<[email protected]>"
95+
DisplayName = "Email DisplayName"
96+
},
97+
@{
98+
Address = "<[email protected]>"
99+
DisplayName = "Email DisplayName"
100+
}
101+
)
102+
103+
$fileBytes1 = [System.IO.File]::ReadAllBytes("<image file path1>")
104+
$fileBytes2 = [System.IO.File]::ReadAllBytes("<image file path2>")
105+
$fileBytes3 = [System.IO.File]::ReadAllBytes("<image file path3>")
106+
107+
$emailAttachment = @(
108+
@{
109+
ContentInBase64 = $fileBytes1
110+
ContentType = "<image/png>"
111+
Name = "<inline-attachment1.png>"
112+
contentId = "<contentId1>"
113+
},
114+
@{
115+
ContentInBase64 = $fileBytes2
116+
ContentType = "<image/png>"
117+
Name = "<inline-attachment2.png>"
118+
contentId = "<contentId2>"
119+
},
120+
@{
121+
ContentInBase64 = $fileBytes3
122+
ContentType = "<image/png>"
123+
Name = "<inline-attachment3.png>"
124+
contentId = "<contentId3>"
125+
}
126+
)
127+
128+
$message = @{
129+
ContentSubject = "Test Email"
130+
RecipientTo = @($emailRecipientTo) # Array of email address objects
131+
SenderAddress = '<[email protected]>'
132+
Attachment = @($emailAttachment) # Array of attachments
133+
ContentHtml = "<html><head><title>Enter title</title></head><body><img src='cid:<contentId1>' alt='Company Logo'/><img src='cid:<contentId2>' alt='Company Logo'/><img src='cid:<contentId3>' alt='Company Logo'/><h1>This is the first email from ACS - Azure PowerShell</h1></body></html>"
134+
ContentPlainText = "This is the first email from ACS - Azure PowerShell"
135+
}
136+
```
137+
138+
Make these replacements in the code:
139+
140+
- Replace `<yourEndpoint>` with your endpoint.
141+
- Replace `<[email protected]> and <[email protected]>` with the email addresses you would like to send a message to.
142+
- Replace `<image file path1>` `<image file path2>` `<image file path3>` with the actual file paths of the attachments you want to send.
143+
- Replace `<image/png>` with the appropriate content types for your attachments.
144+
- Replace `<inline-attachment1.png>` `<inline-attachment2.png>` `<inline-attachment3.png>` with the filenames of your attachments.
145+
- Replace `<contentId1>` `<contentId2>` `<contentId3>` with the Content-ID for your inline attachment.
146+
147+
### Optional parameters
148+
149+
The following optional parameters are available in Azure PowerShell.
150+
151+
- `ContentHtml` can be used to specify the HTML body of the email.
152+
153+
- `ContentPlainText` used to specify the plain text body of the email.
154+
155+
- `Attachment` sets the list of email attachments and inline attachments. This parameter accepts an array of file paths or attachment objects.
156+
157+
>[!NOTE]
158+
> Please note that we limit the total size of an email request (which includes both regular and inline attachments) to 10MB.
159+
160+
- `Header` custom email headers to be passed and sets email importance level (high, normal, or low).
161+
162+
- `RecipientBcc` array of recipients for the BCC field.
163+
164+
- `RecipientCc` array of recipients for the CC field.
165+
166+
- `ReplyTo` array of email addresses where recipients replies will be sent to.
167+
168+
- `UserEngagementTrackingDisabled` indicates whether user engagement tracking should be disabled for this request if the resource-level user engagement tracking setting was already enabled in the control plane.
169+
170+
Also, you can use a list of recipients with `RecipientCc` and `RecipientBcc` similar to `RecipientTo`. There needs to be at least one recipient in `RecipientTo` or `RecipientCc` or `RecipientBcc`.
171+

articles/communication-services/quickstarts/email/send-email-advanced/includes/prepend-java.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ ms.service: azure-communication-services
1212

1313
Get started with Azure Communication Services by using the Communication Services Java Email SDK to send Email messages.
1414

15+
Completing this quick start incurs a small cost of a few USD cents or less in your Azure account.
16+
1517
> [!TIP]
1618
> Jump-start your email sending experience with Azure Communication Services by skipping straight to the [Basic Email Sending](https://github.com/Azure-Samples/communication-services-java-quickstarts/tree/main/send-email) and [Advanced Email Sending](https://github.com/Azure-Samples/communication-services-java-quickstarts/tree/main/send-email-advanced) sample code on GitHub.
1719

articles/communication-services/quickstarts/email/send-email-advanced/includes/prepend-js.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ ms.service: azure-communication-services
1212

1313
Get started with Azure Communication Services by using the Communication Services JS Email client library to send Email messages.
1414

15+
Completing this quick start incurs a small cost of a few USD cents or less in your Azure account.
16+
1517
> [!TIP]
1618
> Jump-start your email sending experience with Azure Communication Services by skipping straight to the [Basic Email Sending](https://github.com/Azure-Samples/communication-services-javascript-quickstarts/tree/main/send-email) and [Advanced Email Sending](https://github.com/Azure-Samples/communication-services-javascript-quickstarts/tree/main/send-email-advanced) sample code on GitHub.
1719

0 commit comments

Comments
 (0)