Skip to content

Commit b1440a4

Browse files
Updating quickstarts to include AzureKeyCredential
1 parent ec61223 commit b1440a4

File tree

4 files changed

+76
-40
lines changed

4 files changed

+76
-40
lines changed

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ EmailSendResult returns the following status on the email operation performed.
4747

4848
Completing this quickstart incurs a small cost of a few USD cents or less in your Azure account.
4949

50-
> [!Note]
50+
> [!NOTE]
5151
> We can also send an email from our own verified domain [Add custom verified domains to Email Communication Service](../add-custom-verified-domains.md).
5252
5353
### Prerequisite check
@@ -117,35 +117,34 @@ EmailClient emailClient = new EmailClientBuilder()
117117
.buildClient();
118118
```
119119

120-
### Option 2: Authenticate using an AzureKeyCredential
120+
### Option 2: Authenticate using Azure Active Directory
121121

122-
Email clients can also be created and authenticated using the endpoint and Azure Key Credential acquired from an Azure Communication Resource in the [Azure portal](https://portal.azure.com/).
122+
A `DefaultAzureCredential` object must be passed to the `EmailClientBuilder` via the `credential()` method. An endpoint must also be set via the `endpoint()` method.
123+
124+
The `AZURE_CLIENT_SECRET`, `AZURE_CLIENT_ID`, and `AZURE_TENANT_ID` environment variables are needed to create a `DefaultAzureCredential` object.
123125

124126
```java
125-
String endpoint = "https://<resource-name>.communication.azure.com";
126-
AzureKeyCredential azureKeyCredential = new AzureKeyCredential("<access-key>");
127+
// You can find your endpoint and access key from your resource in the Azure portal
128+
String endpoint = "https://<resource-name>.communication.azure.com/";
127129
EmailClient emailClient = new EmailClientBuilder()
128130
.endpoint(endpoint)
129-
.credential(azureKeyCredential)
131+
.credential(new DefaultAzureCredentialBuilder().build())
130132
.buildClient();
131133
```
132134

133-
### Option 3: Authenticate using Azure Active Directory
135+
### Option 3: Authenticate using AzureKeyCredential
134136

135-
A `DefaultAzureCredential` object must be passed to the `EmailClientBuilder` via the `credential()` method. An endpoint must also be set via the `endpoint()` method.
136-
137-
The `AZURE_CLIENT_SECRET`, `AZURE_CLIENT_ID`, and `AZURE_TENANT_ID` environment variables are needed to create a `DefaultAzureCredential` object.
137+
Email clients can also be created and authenticated using the endpoint and Azure Key Credential acquired from an Azure Communication Resource in the [Azure portal](https://portal.azure.com/).
138138

139139
```java
140-
// You can find your endpoint and access key from your resource in the Azure portal
141-
String endpoint = "https://<resource-name>.communication.azure.com/";
140+
String endpoint = "https://<resource-name>.communication.azure.com";
141+
AzureKeyCredential azureKeyCredential = new AzureKeyCredential("<access-key>");
142142
EmailClient emailClient = new EmailClientBuilder()
143143
.endpoint(endpoint)
144-
.credential(new DefaultAzureCredentialBuilder().build())
144+
.credential(azureKeyCredential)
145145
.buildClient();
146146
```
147147

148-
149148
For simplicity, this quickstart uses connection strings, but in production environments, we recommend using [service principals](../../../quickstarts/identity/service-principal.md).
150149

151150
## Basic email sending

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ EmailSendResult returns the following status on the email operation performed.
4949

5050
Completing this quick start incurs a small cost of a few USD cents or less in your Azure account.
5151

52-
> [!Note]
52+
> [!NOTE]
5353
> We can also send an email from our own verified domain. [Add custom verified domains to Email Communication Service](../add-azure-managed-domains.md).
5454
5555
### Prerequisite check
@@ -109,21 +109,38 @@ const emailClient = new EmailClient(connectionString);
109109

110110
### Option 2: Authenticate using Azure Active Directory
111111

112-
You can also authenticate with Azure Active Directory using the [Azure Identity library](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity). To use the [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential) provider shown below, or other credential providers provided with the Azure SDK, please install the [`@azure/identity`](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity) package:
112+
You can also authenticate with Azure Active Directory using the [Azure Identity library](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity). To use the [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential) provider in the following snippet, or other credential providers provided with the Azure SDK, install the [`@azure/identity`](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity) package:
113113

114114
```bash
115115
npm install @azure/identity
116116
```
117117

118-
The [`@azure/identity`](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity) package provides a variety of credential types that your application can use to do this. The README for `@azure/identity` provides more details and samples to get you started.
118+
The [`@azure/identity`](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity) package provides various credential types that your application can use to authenticate. The README for `@azure/identity` provides more details and samples to get you started.
119119
`AZURE_CLIENT_SECRET`, `AZURE_CLIENT_ID` and `AZURE_TENANT_ID` environment variables are needed to create a `DefaultAzureCredential` object.
120120

121121
```typescript
122122
import { DefaultAzureCredential } from "@azure/identity";
123123
import { EmailClient } from "@azure/communication-email";
124+
124125
const endpoint = "https://<resource-name>.communication.azure.com";
125126
let credential = new DefaultAzureCredential();
126-
const client = new EmailClient(endpoint, credential);
127+
128+
const emailClient = new EmailClient(endpoint, credential);
129+
```
130+
131+
### Option 3: Authenticate using AzureKeyCredential
132+
133+
Email clients can also be authenticated using an [AzureKeyCredential](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-core/latest/azure.core.html#azure.core.credentials.AzureKeyCredential). Both the `key` and the `endpoint` can be founded on the "Keys" pane under "Settings" in your Communication Services Resource.
134+
135+
```javascript
136+
const { EmailClient } = require("@azure/communication-email");
137+
const { AzureKeyCredential } = require("@azure/core-auth");
138+
require("dotenv").config();
139+
140+
var key = new AzureKeyCredential("<your-key-credential>");
141+
var endpoint = "<your-endpoint-uri>";
142+
143+
const emailClient = new EmailClient(endpoint, key);
127144
```
128145

129146
For simplicity, this quickstart uses connection strings, but in production environments, we recommend using [service principals](../../../quickstarts/identity/service-principal.md).

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

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ms.service: azure-communication-services
1212

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

15-
## Understanding Email Object model
15+
## Understanding the Email Object model
1616

1717
The following classes and interfaces handle some of the major features of the Azure Communication Services Email Client library for C#.
1818

@@ -39,8 +39,8 @@ EmailSendResult returns the following status on the email operation performed.
3939
| NotStarted | We're not sending this status from our service at this time. |
4040
| Running | The email send operation is currently in progress and being processed. |
4141
| Succeeded | The email send operation has completed without error and the email is out for delivery. Any detailed status about the email delivery beyond this stage can be obtained either through Azure Monitor or through Azure Event Grid. [Learn how to subscribe to email events](../handle-email-events.md) |
42-
| Failed | The email send operation was not successful and encountered an error. The email was not sent. The result will contain an error object with more details on the reason for failure or cancellation. |
43-
| Canceled | The email send operation was canceled before it could complete. The email was not sent. The result will contain an error object with more details on the reason for failure or cancellation.|
42+
| Failed | The email send operation wasn't successful and encountered an error. The email wasn't sent. The result contains an error object with more details on the reason for failure or cancellation. |
43+
| Canceled | The email send operation was canceled before it could complete. The email wasn't sent. The result contains an error object with more details on the reason for failure or cancellation.|
4444

4545
## Prerequisites
4646

@@ -49,13 +49,16 @@ EmailSendResult returns the following status on the email operation performed.
4949
- An Azure Email Communication Services Resource created and ready with a provisioned domain [Get started with Creating Email Communication Resource](../create-email-communication-resource.md)
5050
- An active 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)
5151

52+
Completing this quick start incurs a small cost of a few USD cents or less in your Azure account.
53+
54+
> [!NOTE]
55+
> We can also send an email from our own verified domain. [Add custom verified domains to Email Communication Service](../add-azure-managed-domains.md).
56+
5257
### Prerequisite check
5358

5459
- In a terminal or command window, run the `dotnet` command to check that the .NET client library is installed.
5560
- To view the subdomains associated 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.
5661

57-
Completing this quick start incurs a small cost of a few USD cents or less in your Azure account.
58-
5962
### Create a new C# application
6063
In a console window (such as cmd, PowerShell, or Bash), use the `dotnet new` command to create a new console app with the name `EmailQuickstart`. This command creates a simple "Hello World" C# project with a single source file: **Program.cs**.
6164

@@ -108,7 +111,7 @@ namespace SendEmail
108111

109112
### Option 1: Authenticate using a connection string
110113

111-
Open **Program.cs** in a text editor and replace the body of the `Main` method with code to initialize an `EmailClient` with your connection string. The code below retrieves the connection string for the resource from an environment variable named `COMMUNICATION_SERVICES_CONNECTION_STRING`. Learn how to [manage your resource's connection string](../../create-communication-resource.md#store-your-connection-string).
114+
Open **Program.cs** in a text editor and replace the body of the `Main` method with code to initialize an `EmailClient` with your connection string. The following code retrieves the connection string for the resource from an environment variable named `COMMUNICATION_SERVICES_CONNECTION_STRING`. Learn how to [manage your resource's connection string](../../create-communication-resource.md#store-your-connection-string).
112115

113116

114117

@@ -121,7 +124,7 @@ EmailClient emailClient = new EmailClient(connectionString);
121124

122125
### Option 2: Authenticate using Azure Active Directory
123126

124-
To authenticate using Azure Active Directory, install the Azure.Identity library package for .NET by using the `dotnet add package` command.
127+
To authenticate using Azure Active Directory, install the `Azure.Identity` library package for .NET by using the `dotnet add package` command.
125128

126129
```console
127130
dotnet add package Azure.Identity
@@ -136,6 +139,17 @@ string resourceEndpoint = "<ACS_RESOURCE_ENDPOINT>";
136139
EmailClient emailClient = new EmailClient(new Uri(resourceEndpoint), new DefaultAzureCredential());
137140
```
138141

142+
### Option 3: Authenticate using AzureKeyCredential
143+
144+
Email clients can also be authenticated using an [AzureKeyCredential](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-core/latest/azure.core.html#azure.core.credentials.AzureKeyCredential). Both the `key` and the `endpoint` can be founded on the "Keys" pane under "Settings" in your Communication Services Resource.
145+
146+
```csharp
147+
var key = new AzureKeyCredential("<your-key-credential>");
148+
var endpoint = new Uri("<your-endpoint-uri>");
149+
150+
var emailClient = new EmailClient(endpoint, key);
151+
```
152+
139153
## Basic Email Sending
140154

141155
### Construct your email message
@@ -160,8 +174,8 @@ var recipient = "[email protected]";
160174
### Send and get the email send status
161175

162176
To send an email message, you need to:
163-
- Call SendSync method which sends the email request as an asynchronous operation. Call with Azure.WaitUntil.Completed if your method should wait to return until the long-running operation has completed on the service; Call with Azure.WaitUntil.Started if your method should return after starting the operation.
164-
- SendAsync method returns EmailSendOperation which returns "Succeeded" EmailSendStatus if email is out for delivery. Add this code to the end of `Main` method in **Program.cs**:
177+
- Call SendSync method that sends the email request as an asynchronous operation. Call with Azure.WaitUntil.Completed if your method should wait to return until the long-running operation has completed on the service. Call with Azure.WaitUntil.Started if your method should return after starting the operation.
178+
- SendAsync method returns EmailSendOperation that returns "Succeeded" EmailSendStatus if email is out for delivery. Add this code to the end of `Main` method in **Program.cs**:
165179

166180
```csharp
167181
try
@@ -193,20 +207,20 @@ catch (Exception ex)
193207

194208
### Getting email delivery status
195209

196-
EmailSendOperation only returns email operation status. To get the actual email delivery status you can subscribe to "EmailDeliveryReportReceived" event which is generated when the email delivery is completed and the event returns the following delivery state :
210+
EmailSendOperation only returns email operation status. To get the actual email delivery status, you can subscribe to "EmailDeliveryReportReceived" event that is generated when the email delivery is completed. The event returns the following delivery state:
197211

198212
- Delivered.
199213
- Failed.
200214
- Quarantined.
201215

202216
See [Handle Email Events](../handle-email-events.md) for details.
203217

204-
You can also now subscribe to Email Operational logs which provides information related to delivery metrics for messages sent from the Email service.
218+
You can also now subscribe to Email Operational logs that provide information related to delivery metrics for messages sent from the Email service.
205219

206220
- Email Send Mail operational logs - provides detailed information related to the Email service send mail requests.
207221
- Email Status Update operational logs - provides message and recipient level delivery status updates related to the Email service send mail requests.
208222

209-
Please see how to [Get started with log analytics in Azure Communication Service](../../../concepts/logging-and-diagnostics.md)
223+
See how to [Get started with log analytics in Azure Communication Service](../../../concepts/logging-and-diagnostics.md)
210224

211225
### Run the code
212226

@@ -226,8 +240,8 @@ You can download the sample app from [GitHub](https://github.com/Azure-Samples/c
226240

227241
When you call SendAsync with Azure.WaitUntil.Started, your method returns back after starting the operation. The method returns EmailSendOperation object. You can call UpdateStatusAsync method to refresh the email operation status.
228242

229-
The returned EmailSendOperation object contains an EmailSendStatus object which contains:
230-
- Current status of the email send operation.
243+
The returned EmailSendOperation object contains an EmailSendStatus object that contains:
244+
- Current status of the Email Send operation.
231245
- An error object with failure details if the current status is in a failed state.
232246

233247
```csharp
@@ -358,7 +372,7 @@ catch (Exception ex)
358372

359373
### Send an email message to multiple recipients
360374

361-
We can define multiple recipients by adding additional EmailAddresses to the EmailRecipients object. These addresses can be added as `To`, `CC`, or `BCC` recipients.
375+
We can define multiple recipients by adding more EmailAddresses to the EmailRecipients object. These addresses can be added as `To`, `CC`, or `BCC` recipients.
362376

363377
```csharp
364378
var toRecipients = new List<EmailAddress>
@@ -380,7 +394,7 @@ var bccRecipients = new List<EmailAddress>
380394
EmailRecipients emailRecipients = new EmailRecipients(toRecipients, ccRecipients, bccRecipients);
381395
```
382396

383-
You can download the sample app demonstrating this from [GitHub](https://github.com/Azure-Samples/communication-services-dotnet-quickstarts/tree/main/SendEmailAdvanced/SendEmailToMultipleRecipients)
397+
You can download the sample app demonstrating this action from [GitHub](https://github.com/Azure-Samples/communication-services-dotnet-quickstarts/tree/main/SendEmailAdvanced/SendEmailToMultipleRecipients)
384398

385399

386400
### Send an email message with attachments
@@ -397,6 +411,6 @@ emailMessage.Attachments.Add(emailAttachment);
397411

398412
```
399413

400-
You can download the sample app demonstrating this from [GitHub](https://github.com/Azure-Samples/communication-services-dotnet-quickstarts/tree/main/SendEmailAdvanced/SendEmailWithAttachments)
414+
You can download the sample app demonstrating this action from [GitHub](https://github.com/Azure-Samples/communication-services-dotnet-quickstarts/tree/main/SendEmailAdvanced/SendEmailWithAttachments)
401415

402416

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ The `response.status` values are explained further in the following table.
104104

105105
Completing this quick start incurs a small cost of a few USD cents or less in your Azure account.
106106

107+
> [!NOTE]
108+
> We can also send an email from our own verified domain. [Add custom verified domains to Email Communication Service](../add-azure-managed-domains.md).
109+
107110
### Prerequisite check
108111
- In a terminal or command window, run the `python --version` command to check that Python is installed.
109112
- 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.
@@ -170,18 +173,21 @@ from azure.identity import DefaultAzureCredential
170173

171174
# To use Azure Active Directory Authentication (DefaultAzureCredential) make sure to have AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET as env variables.
172175
endpoint = "https://<resource-name>.communication.azure.com"
173-
client = EmailClient(endpoint, DefaultAzureCredential())
176+
email_client = EmailClient(endpoint, DefaultAzureCredential())
174177
```
175178

176179
### Option 3: Authenticate using AzureKeyCredential
177-
Email clients can also be authenticated using an [AzureKeyCredential](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-core/latest/azure.core.html#azure.core.credentials.AzureKeyCredential).
180+
181+
Email clients can also be authenticated using an [AzureKeyCredential](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-core/latest/azure.core.html#azure.core.credentials.AzureKeyCredential). Both the `key` and the `endpoint` can be founded on the "Keys" pane under "Settings" in your Communication Services Resource.
178182

179183
```python
180184
from azure.communication.email import EmailClient
181185
from azure.core.credentials import AzureKeyCredential
182-
credential = AzureKeyCredential("<api_key>")
183-
endpoint = "https://<resource-name>.communication.azure.com/"
184-
client = EmailClient(endpoint, credential);
186+
187+
key = AzureKeyCredential("<your-key-credential>");
188+
endpoint = "<your-endpoint-uri>";
189+
190+
email_client = EmailClient(endpoint, key);
185191
```
186192

187193
For simplicity, this quickstart uses connection strings, but in production environments, we recommend using [service principals](../../../quickstarts/identity/service-principal.md).

0 commit comments

Comments
 (0)