Skip to content

Commit c9bd9d9

Browse files
committed
Email Service - Send email - Update quick start to recommend customers to use manual pooling - updated tab names
1 parent 120367c commit c9bd9d9

File tree

2 files changed

+93
-4
lines changed

2 files changed

+93
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@ var emailClient = new EmailClient(endpoint, key);
152152
---
153153

154154
> [!NOTE]
155-
> It is recommended to use the manual polling (Send Email and get status async) to send email.
155+
> It is recommended to use the manual polling (Send Email with asynchronous status polling) to send email.
156156
157-
#### [Send Email and get status async](#tab/send-email-and-get-status-async)
157+
#### [Send Email with asynchronous status polling](#tab/send-email-and-get-status-async)
158158

159-
[!INCLUDE [polling-net](../send-email-advanced/includes/polling-net.md)]
159+
[!INCLUDE [polling-net](../send-email-advanced/includes/asynchronous-status-polling-net.md)]
160160

161-
#### [Send Email and get status sync](#tab/send-smail-and-get-status-sync)
161+
#### [Send Email with synchronous status polling](#tab/send-smail-and-get-status-sync)
162162

163163
## Basic email sending
164164

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
title: include file
3+
description: Manual polling .NET SDK include file
4+
author: natekimball-msft
5+
manager: koagbakp
6+
services: azure-communication-services
7+
ms.author: natekimball
8+
ms.date: 04/07/2023
9+
ms.topic: include
10+
ms.service: azure-communication-services
11+
---
12+
13+
## Basic email sending
14+
15+
### Construct your email message
16+
17+
To send an email message, you need to:
18+
- Define the email subject and body.
19+
- Define your Sender Address. Construct your email message with your Sender information you get your MailFrom address from your verified domain.
20+
- Define the Recipient Address.
21+
- Call the SendAsync method. Add this code to the end of `Main` method in **Program.cs**:
22+
23+
Replace with your domain details and modify the content, recipient details as required
24+
```csharp
25+
26+
//Replace with your domain and modify the content, recipient details as required
27+
28+
var subject = "Welcome to Azure Communication Service Email APIs.";
29+
var htmlContent = "<html><body><h1>Quick send email test</h1><br/><h4>This email message is sent from Azure Communication Service Email.</h4><p>This mail was sent using .NET SDK!!</p></body></html>";
30+
var sender = "[email protected]";
31+
var recipient = "[email protected]";
32+
33+
```
34+
### Send and get the email send status
35+
36+
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.
37+
38+
The returned EmailSendOperation object contains an EmailSendStatus object that contains:
39+
- Current status of the Email Send operation.
40+
- An error object with failure details if the current status is in a failed state.
41+
42+
```csharp
43+
44+
/// Send the email message with WaitUntil.Started
45+
EmailSendOperation emailSendOperation = await emailClient.SendAsync(
46+
Azure.WaitUntil.Started,
47+
sender,
48+
recipient,
49+
subject,
50+
htmlContent);
51+
52+
/// Call UpdateStatus on the email send operation to poll for the status
53+
/// manually.
54+
try
55+
{
56+
while (true)
57+
{
58+
await emailSendOperation.UpdateStatusAsync();
59+
if (emailSendOperation.HasCompleted)
60+
{
61+
break;
62+
}
63+
await Task.Delay(100);
64+
}
65+
66+
if (emailSendOperation.HasValue)
67+
{
68+
Console.WriteLine($"Email queued for delivery. Status = {emailSendOperation.Value.Status}");
69+
}
70+
}
71+
catch (RequestFailedException ex)
72+
{
73+
Console.WriteLine($"Email send failed with Code = {ex.ErrorCode} and Message = {ex.Message}");
74+
}
75+
76+
/// Get the OperationId so that it can be used for tracking the message for troubleshooting
77+
string operationId = emailSendOperation.Id;
78+
Console.WriteLine($"Email operation id = {operationId}");
79+
```
80+
81+
Run the application from your application directory with the `dotnet run` command.
82+
83+
```console
84+
dotnet run
85+
```
86+
87+
### Sample code
88+
89+
You can download the sample app from [GitHub](https://github.com/Azure-Samples/communication-services-dotnet-quickstarts/tree/main/SendEmailAdvanced/SendEmailWithManualPollingForStatus)

0 commit comments

Comments
 (0)