Sending emails with SendGrid on Azure using C# async, await

async-await, azure, c#, sendgrid

Solution

Currently the SendGrid C# library doesn't haven't async methods because we wanted to maintain compatibility with .NET 4.0.

You could easily make this change yourself. In fact, here's a commit that I later reverted after we decided to stick with .NET 4.0.

Update: As of Oct 24 2013 and sendgrid-csharp 1.2.1, there is a DeliverAsync method available

Problem

I'm following this tutorial to send emails from my Azure web role using SendGrid. This is the relevant part from the tutorial: ``` // Create credentials, specifying your user name and password. var credentials = new NetworkCredential("username", "password"); // Create an REST transport for sending email. var transportREST = REST.GetInstance(credentials); // Send the email. transportREST.Deliver(myMessage); ``` It seems to me that the `transportREST.Deliver` function is synchronous. Since it's performing IO I'd prefer to use the new .NET 4.5 async, await instead (all my other code is completely asynchronous). Is this possible? Is there an async API for SendGrid or some way to wrap the existing call?

Original source