Skip to content

Commit d695189

Browse files
Adjusting dotnet doc based on discussion
1 parent bbafa6b commit d695189

File tree

2 files changed

+87
-106
lines changed

2 files changed

+87
-106
lines changed

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -166,30 +166,30 @@ try
166166

167167
Duration timeElapsed = Duration.ofSeconds(0);
168168

169-
while (pollResponse == null
170-
|| pollResponse.getStatus() == LongRunningOperationStatus.NOT_STARTED
171-
|| pollResponse.getStatus() == LongRunningOperationStatus.IN_PROGRESS)
172-
{
173-
pollResponse = poller.poll();
174-
System.out.println("Email send poller status: " + pollResponse.getStatus());
175-
176-
Thread.sleep(POLLER_WAIT_TIME.toMillis());
177-
timeElapsed = timeElapsed.plus(POLLER_WAIT_TIME);
169+
while (pollResponse == null
170+
|| pollResponse.getStatus() == LongRunningOperationStatus.NOT_STARTED
171+
|| pollResponse.getStatus() == LongRunningOperationStatus.IN_PROGRESS)
172+
{
173+
pollResponse = poller.poll();
174+
System.out.println("Email send poller status: " + pollResponse.getStatus());
178175

179-
if (timeElapsed.compareTo(POLLER_WAIT_TIME.multipliedBy(18)) >= 0)
180-
{
181-
throw new RuntimeException("Polling timed out.");
182-
}
183-
}
176+
Thread.sleep(POLLER_WAIT_TIME.toMillis());
177+
timeElapsed = timeElapsed.plus(POLLER_WAIT_TIME);
184178

185-
if (poller.getFinalResult().getStatus() == EmailSendStatus.SUCCEEDED)
186-
{
187-
System.out.printf("Successfully sent the email (operation id: %s)", poller.getFinalResult().getId());
188-
}
189-
else
179+
if (timeElapsed.compareTo(POLLER_WAIT_TIME.multipliedBy(18)) >= 0)
190180
{
191-
throw new RuntimeException(poller.getFinalResult().getError().getMessage());
181+
throw new RuntimeException("Polling timed out.");
192182
}
183+
}
184+
185+
if (poller.getFinalResult().getStatus() == EmailSendStatus.SUCCEEDED)
186+
{
187+
System.out.printf("Successfully sent the email (operation id: %s)", poller.getFinalResult().getId());
188+
}
189+
else
190+
{
191+
throw new RuntimeException(poller.getFinalResult().getError().getMessage());
192+
}
193193
}
194194
catch (Exception exception)
195195
{

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

Lines changed: 67 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ var endpoint = new Uri("<your-endpoint-uri>");
150150
var emailClient = new EmailClient(endpoint, key);
151151
```
152152

153-
## Basic Email Sending
153+
## Basic email sending
154154

155155
### Construct your email message
156156

@@ -175,27 +175,25 @@ var recipient = "[email protected]";
175175

176176
To send an email message, you need to:
177177
- 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**:
178+
- SendAsync method returns EmailSendOperation that returns "Succeeded" EmailSendStatus if email is out for delivery and throws an exception otherwise. Add this code to the end of `Main` method in **Program.cs**:
179179

180180
```csharp
181181
try
182182
{
183-
Console.WriteLine("Sending email...");
184-
EmailSendOperation emailSendOperation = await emailClient.SendAsync(Azure.WaitUntil.Completed, sender, recipient, subject, htmlContent);
185-
EmailSendResult statusMonitor = emailSendOperation.Value;
186-
187-
string operationId = emailSendOperation.Id;
188-
var emailSendStatus = statusMonitor.Status;
183+
Console.WriteLine("Sending email...");
184+
EmailSendOperation emailSendOperation = await emailClient.SendAsync(
185+
Azure.WaitUntil.Completed,
186+
sender,
187+
recipient,
188+
subject,
189+
htmlContent);
190+
EmailSendResult statusMonitor = emailSendOperation.Value;
191+
192+
Console.WriteLine($"Email Sent. Status = {emailSendOperation.Value.Status}");
189193

190-
if (emailSendStatus == EmailSendStatus.Succeeded)
191-
{
192-
Console.WriteLine($"Email send operation succeeded with OperationId = {operationId}.\nEmail is out for delivery.");
193-
}
194-
else
195-
{
196-
Console.WriteLine($"Failed to send email.\n OperationId = {operationId}.\n Status = {emailSendStatus}.");
197-
return;
198-
}
194+
/// Get the OperationId so that it can be used for tracking the message for troubleshooting
195+
string operationId = emailSendOperation.Id;
196+
Console.WriteLine($"Email operation id = {operationId}");
199197
}
200198
catch (RequestFailedException ex)
201199
{
@@ -244,50 +242,41 @@ The returned EmailSendOperation object contains an EmailSendStatus object that c
244242
- An error object with failure details if the current status is in a failed state.
245243

246244
```csharp
245+
Console.WriteLine("Sending email with Async no Wait...");
246+
EmailSendOperation emailSendOperation = await emailClient.SendAsync(
247+
Azure.WaitUntil.Started,
248+
sender,
249+
recipient,
250+
subject,
251+
htmlContent);
252+
253+
/// Call UpdateStatus on the email send operation to poll for the status
254+
/// manually.
247255
try
248256
{
249-
Console.WriteLine("Sending email with Async no Wait...");
250-
EmailSendOperation emailSendOperation = await emailClient.SendAsync(Azure.WaitUntil.Started, sender, recipient, subject, htmlContent);
251-
252-
var cancellationToken = new CancellationTokenSource(TimeSpan.FromMinutes(2));
253-
254-
// Poll for email send status manually
255-
while (!cancellationToken.IsCancellationRequested)
256-
{
257-
await emailSendOperation.UpdateStatusAsync();
258-
if (emailSendOperation.HasCompleted)
259-
{
260-
break;
261-
}
262-
Console.WriteLine("Email send operation is still running...");
263-
await Task.Delay(1000);
264-
}
265-
266-
if (emailSendOperation.HasValue)
267-
{
268-
EmailSendResult statusMonitor = emailSendOperation.Value;
269-
string operationId = emailSendOperation.Id;
270-
var emailSendStatus = statusMonitor.Status;
271-
272-
if (emailSendStatus == EmailSendStatus.Succeeded)
257+
while (true)
273258
{
274-
Console.WriteLine($"Email send operation succeeded with OperationId = {operationId}.\nEmail is out for delivery.");
259+
await emailSendOperation.UpdateStatusAsync();
260+
if (emailSendOperation.HasCompleted)
261+
{
262+
break;
263+
}
264+
await Task.Delay(100);
275265
}
276-
else
266+
267+
if (emailSendOperation.HasValue)
277268
{
278-
Console.WriteLine($"Failed to send email.\n OperationId = {operationId}.\n Status = {emailSendStatus}.");
279-
return;
269+
Console.WriteLine($"Email queued for delivery. Status = {emailSendOperation.Value.Status}");
280270
}
281-
}
282-
else if (cancellationToken.IsCancellationRequested)
283-
{
284-
Console.WriteLine($"We have timed out while polling for email status");
285-
}
286271
}
287272
catch (RequestFailedException ex)
288273
{
289-
Console.WriteLine($"Email send operation failed with error code: {ex.ErrorCode}, message: {ex.Message}");
274+
Console.WriteLine($"Email send failed with Code = {ex.ErrorCode} and Message = {ex.Message}");
290275
}
276+
277+
/// Get the OperationId so that it can be used for tracking the message for troubleshooting
278+
string operationId = emailSendOperation.Id;
279+
Console.WriteLine($"Email operation id = {operationId}");
291280
```
292281

293282

@@ -304,64 +293,56 @@ You can download the sample app from [GitHub](https://github.com/Azure-Samples/c
304293

305294
### Send an email message using the object model to construct the email payload
306295

307-
- Construct the email content and body using EmailContent.
296+
- Construct the email subject and body using EmailContent.
308297
- Add Recipients.
309298
- Set email importance through custom headers.
310299
- Construct your email message using your sender email address, defined in the MailFrom list of the domain linked in your Communication Services Resource.
311300
- Include your EmailContent and EmailRecipients, optionally adding attachments.
312301

313302
```csharp
314-
315-
EmailContent emailContent = new EmailContent("Welcome to Azure Communication Service Email APIs.");
316-
317303
var subject = "Welcome to Azure Communication Service Email APIs.";
318-
319304
var emailContent = new EmailContent(subject)
320305
{
321-
PlainText = "This email message is sent from Azure Communication Service Email using .NET SDK.",
322-
Html = "<html><body><h1>Quick send email test</h1><br/><h4>This email message is sent from Azure Communication Service Email using .NET SDK.</h4></body></html>"
306+
PlainText = "This email message is sent from Azure Communication Service Email using .NET SDK.",
307+
Html = "<html><body><h1>Quick send email test</h1><br/><h4>This email message is sent from Azure Communication Service Email using .NET SDK.</h4></body></html>"
323308
};
324-
325-
var sender = "[email protected]";
326309

327-
List<EmailAddress> emailAddresses = new List<EmailAddress> { new EmailAddress("[email protected]") { DisplayName = "Friendly Display Name" }};
310+
List<EmailAddress> emailAddresses = new List<EmailAddress>
311+
{
312+
new EmailAddress("[email protected]", "Friendly Display Name")
313+
};
328314

329315
EmailRecipients emailRecipients = new EmailRecipients(emailAddresses);
330316

331317
var emailMessage = new EmailMessage(sender, emailRecipients, emailContent)
332318
{
333-
// Header name is "x-priority" or "x-msmail-priority"
334-
// Header value is a number from 1 to 5. 1 or 2 = High, 3 = Normal, 4 or 5 = Low
335-
// Not all email clients recognize this header directly (outlook client does recognize)
336-
Headers =
337-
{
338-
// Set Email Importance to High
339-
{ "x-priority", "1" },
340-
{ "", "" }
341-
}
319+
// Header name is "x-priority" or "x-msmail-priority"
320+
// Header value is a number from 1 to 5. 1 or 2 = High, 3 = Normal, 4 or 5 = Low
321+
// Not all email clients recognize this header directly (outlook client does recognize)
322+
Headers =
323+
{
324+
// Set Email Importance to High
325+
{ "x-priority", "1" },
326+
{ "", "" }
327+
}
342328
};
343329

344330
try
345331
{
346-
Console.WriteLine("Sending email to multiple recipients...");
347-
EmailSendOperation emailSendOperation = await emailClient.SendAsync(Azure.WaitUntil.Completed, emailMessage);
348-
EmailSendResult statusMonitor = emailSendOperation.Value;
349-
350-
string operationId = emailSendOperation.Id;
351-
var emailSendStatus = statusMonitor.Status;
352-
353-
if (emailSendStatus == EmailSendStatus.Succeeded)
354-
{
355-
Console.WriteLine($"Email send operation succeeded with OperationId = {operationId}.\nEmail is out for delivery.");
356-
}
357-
else
358-
{
359-
Console.WriteLine($"Failed to send email. \n OperationId = {operationId}. \n Status = {emailSendStatus}");
360-
return;
361-
}
332+
Console.WriteLine("Sending email to multiple recipients...");
333+
EmailSendOperation emailSendOperation = emailClient.Send(
334+
WaitUntil.Completed,
335+
emailMessage);
336+
337+
Console.WriteLine($"Email Sent. Status = {emailSendOperation.Value.Status}");
338+
339+
/// Get the OperationId so that it can be used for tracking the message for troubleshooting
340+
string operationId = emailSendOperation.Id;
341+
Console.WriteLine($"Email operation id = {operationId}");
362342
}
363343
catch (RequestFailedException ex)
364344
{
345+
/// OperationID is contained in the exception message and can be used for troubleshooting purposes
365346
Console.WriteLine($"Email send operation failed with error code: {ex.ErrorCode}, message: {ex.Message}");
366347
}
367348

0 commit comments

Comments
 (0)