Skip to content

Commit 041ea0a

Browse files
authored
Merge pull request #291369 from Deepika0530/SendEmail-AzurePowerShell-Doc
Send email azure power shell doc
2 parents a0cf433 + 95caea2 commit 041ea0a

File tree

3 files changed

+189
-3
lines changed

3 files changed

+189
-3
lines changed
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
---
2+
title: include file
3+
description: include file
4+
author: v-deepikal
5+
manager: komivi.agbakpem
6+
services: azure-communication-services
7+
ms.author: v-deepikal
8+
ms.date: 12/04/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
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+
54+
$message = @{
55+
ContentSubject = "Test Email"
56+
RecipientTo = @($emailRecipientTo) # Array of email address objects
57+
SenderAddress = '<[email protected]>'
58+
ContentPlainText = "This is the first email from ACS - Azure PowerShell"
59+
}
60+
61+
Send-AzEmailServicedataEmail -Message $Message -endpoint "<yourEndpoint>"
62+
```
63+
64+
Make these replacements in the code:
65+
66+
- Replace `<yourEndpoint>` with your endpoint.
67+
- Replace `<[email protected]>` with the email address you would like to send a message to.
68+
- Replace `<[email protected]>` with the MailFrom address of your verified domain.
69+
70+
Queues an email message to be sent to one or more recipients with all the fields.
71+
72+
```azurepowershell-interactive
73+
$emailRecipientTo = @(
74+
@{
75+
Address = "<[email protected]>"
76+
DisplayName = "Email DisplayName"
77+
},
78+
@{
79+
Address = "<[email protected]>"
80+
DisplayName = "Email DisplayName"
81+
}
82+
)
83+
84+
$fileBytes1 = [System.IO.File]::ReadAllBytes("<file path>")
85+
86+
$fileBytes2 = [System.IO.File]::ReadAllBytes("<image file path>")
87+
88+
$emailAttachment = @(
89+
@{
90+
ContentInBase64 = $fileBytes1
91+
ContentType = "<text/plain>"
92+
Name = "<test.txt>"
93+
},
94+
@{
95+
ContentInBase64 = $fileBytes2
96+
ContentType = "<image/png>"
97+
Name = "<inline-attachment.png>"
98+
contentId = "<inline-attachment>"
99+
}
100+
)
101+
102+
$headers = @{
103+
"Key1" = "Value1"
104+
"Key2" = "Value2"
105+
"Importance" = "high"
106+
}
107+
108+
$emailRecipientBcc = @(
109+
@{
110+
Address = "<[email protected]>"
111+
DisplayName = "Email DisplayName"
112+
}
113+
)
114+
115+
$emailRecipientCc = @(
116+
@{
117+
Address = "<[email protected]>"
118+
DisplayName = "Email DisplayName"
119+
}
120+
)
121+
122+
$emailRecipientReplyTo = @(
123+
@{
124+
Address = "<[email protected]>"
125+
DisplayName = "Email DisplayName"
126+
}
127+
)
128+
129+
$message = @{
130+
ContentSubject = "Test Email"
131+
RecipientTo = @($emailRecipientTo) # Array of email address objects
132+
SenderAddress = '<[email protected]>'
133+
Attachment = @($emailAttachment) # Array of attachments
134+
ContentHtml = "<html><head><title>Enter title</title></head><body><img src='cid:inline-attachment' alt='Company Logo'/><h1>This is the first email from ACS - Azure PowerShell</h1></body></html>"
135+
ContentPlainText = "This is the first email from ACS - Azure PowerShell"
136+
Header = $headers # Importance = high/medium/low or X-Priority = 2/3/4
137+
RecipientBcc = @($emailRecipientBcc) # Array of email address objects
138+
RecipientCc = @($emailRecipientCc) # Array of email address objects
139+
ReplyTo = @($emailRecipientReplyTo) # Array of email address objects
140+
UserEngagementTrackingDisabled = $true
141+
}
142+
143+
Send-AzEmailServicedataEmail -Message $Message -endpoint "<yourEndpoint>"
144+
```
145+
146+
Make these replacements in the code:
147+
148+
- Replace `<yourEndpoint>` with your endpoint.
149+
- Replace `<[email protected]> and <[email protected]>` with the email addresses you would like to send a message to.
150+
- Replace `<file path> and <image file path>` with the actual file paths of the attachments you want to send.
151+
- Replace `<text/plain> and <image/png>` with the appropriate content types for your attachments.
152+
- Replace `<test.txt> and <inline-attachment.png>` with the filenames of your attachments.
153+
- Replace `<inline-attachment>` with the Content-ID for your inline attachment.
154+
- Replace `<[email protected]>` with the email address you want to send the message to as BCC.
155+
- Replace `<[email protected]>` with the email address you want to send the message to as CC.
156+
- Replace `<[email protected]>` with the email address you want replies to be sent to.
157+
- Replace `<[email protected]>` with the MailFrom address of your verified domain.
158+
159+
### Optional parameters
160+
161+
The following optional parameters are available in Azure PowerShell.
162+
163+
- `ContentHtml` can be used to specify the HTML body of the email.
164+
165+
- `ContentPlainText` used to specify the plain text body of the email.
166+
167+
- `Attachment` sets the list of email attachments. This parameter accepts an array of file paths or attachment objects. Please note that we limit the total size of an email request (which includes both regular and inline attachments) to 10MB.
168+
169+
- `Header` custom email headers to be passed and sets email importance level (high, normal, or low).
170+
171+
- `RecipientBcc` array of recipients for the BCC field.
172+
173+
- `RecipientCc` array of recipients for the CC field.
174+
175+
- `ReplyTo` array of email addresses where recipients replies will be sent to.
176+
177+
- `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.
178+
179+
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`.
180+

articles/communication-services/quickstarts/email/send-email.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ms.date: 04/10/2023
1010
ms.topic: quickstart
1111
ms.service: azure-communication-services
1212
ms.custom: devx-track-extended-java, devx-track-js, devx-track-python
13-
zone_pivot_groups: acs-azcli-js-csharp-java-python-portal-nocode
13+
zone_pivot_groups: acs-azcli-js-csharp-java-python-portal-nocode-ps
1414
---
1515

1616
# Quickstart: How to send an email using Azure Communication Services
@@ -47,6 +47,10 @@ This quickstart describes how to send email using our Email SDKs.
4747
[!INCLUDE [Azure Logic Apps](./includes/send-email-logic-app.md)]
4848
::: zone-end
4949

50+
::: zone pivot="platform-powershell"
51+
[!INCLUDE [Send email with Azure PowerShell](./includes/send-email-powershell.md)]
52+
::: zone-end
53+
5054
## Troubleshooting
5155

5256
### Email Delivery

articles/zone-pivot-groups.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ groups:
613613
title: Java
614614
- id: programming-language-python
615615
title: Python
616-
- id: acs-azcli-js-csharp-java-python-portal-nocode
616+
- id: acs-azcli-js-csharp-java-python-portal-nocode-ps
617617
title: Programming languages
618618
prompt: Choose a programming language
619619
pivots:
@@ -630,7 +630,9 @@ groups:
630630
- id: programming-language-python
631631
title: Python
632632
- id: platform-nocode
633-
title: Power Platform
633+
title: Power Platform
634+
- id: platform-powershell
635+
title: Azure PowerShell
634636
- id: acs-plat-web-ios-android
635637
title: Platform
636638
prompt: Choose a platform

0 commit comments

Comments
 (0)