Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 820
talkol Avatar asked Aug 21 '13 16:08

talkol


1 Answers

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

like image 129
bwest Avatar answered Nov 14 '22 22:11

bwest