I had the exact same issue, but when I read this thread I learned that WaitUntil.Started is what I needed. Works great now. Thank you for posting the great question and to Microsoft for the great answer.
Azure Email Communication Service is slow (30 seconds to send email)
When I use Azure Email Communication Services, it takes approximately 30 seconds to send per email, which is extremely slow. I've tried reusing the emailClient to see if subsequent emails are faster, but they're not. I've tried both the default Microsoft "DoNotReply" sender address as well as a custom domain sender address, and they both take about the same time.
Here is the line of code that takes so long.
var emailResult = await emailClient.SendAsync(Azure.WaitUntil.Completed, emailMessage);
This poses a few questions:
- Is this because it's currently in Preview, or is this how long I should expect?
- Perhaps I need to configure something in Azure?
- Something else I haven't thought of?
Azure Communication Services
Developer technologies | ASP.NET | ASP.NET Core
Azure App Service
3 answers
Sort by: Most helpful
-
-
SnehaAgrawal-MSFT 22,706 Reputation points Moderator
2023-03-16T16:38:11.6133333+00:00 37298796 Sure, Thanks for reply! Email send is an asynchronous operation, which means our service accepts it immediately but will asynchronously try to send it in the backend.
You can poll for the status of email send request. If you look at the above call, it does automatic polling in the backend (since first parameter is
WaitUntil.Completed
).You can also use
WaitUntil.Started
which will return immediately. In this case, they can poll for the status usingEmailSendOperation.UpdateStatus()
at a faster interval if you want.There is a sample for this in our github samples - communication-services-dotnet-quickstarts/SendEmailAdvanced/SendEmailWithManualPollingForStatus at main · Azure-Samples/communication-services-dotnet-quickstarts · GitHub
Let us know if further query or issue remains.
-
Michael Schaeufler 0 Reputation points
2024-02-13T07:22:19.3166667+00:00 Hello @SnehaAgrawal-MSFT
I'm running into the same problem with Azure Communication Service for email and python. That has the two effects:
- Bad experiance for my app users to wait for 15-20 sec. for all functions that trigger an email in the backend (e.g. PW Reset)
- some functions in the backend run into a timeout while waiting for Azure Communication Service status.
I use the sample code for python:
message = { "content": { "subject": "This is the subject", "plainText": "This is the body", "html": "<html><h1>This is the body</h1></html>" }, "recipients": { "to": / "cc": / "bcc": [...] }, "senderAddress": "******@contoso.com" } poller = email_client.begin_send(message) #result = poller.result() -->Commented out programme command
I'm wondering if this is a good idea to commented the result poller. At least it solved my problem of the delay in the program.
Is email_client.begin_send function having a configuration like the sms service with wait_until_started=True as discripted here: Why sending a mail using Azure email communication service is too slow?