Some time ago I described how you could integrate SendGrid service with Azure Functions (article: Sending emails from Azure Functions v2 – SendGrid link). Mentioned article is still valid in the scope of SendGrid service configuration. I need to add a part related to integration with Azure Functions v2. This version is generally available from the last few months and it introduced some architectural changes.

In the previous version of functions (v1), the code that has been responsible for integration with different services providers was part of the runtime. Each time when Microsoft wanted to change something related to integration he needed to change the whole functions platform. In the second version of functions code responsible for integration have been moved outside platform. This change allowed us to introduce new services that we will be able to integrate with Azure Functions. Moreover, it changed a bit way how we will use this part in the code.

Because of this change, we need now to install correct NuGet package. In case of SendGrid it is Microsoft.Azure.WebJobs.Extensions.SendGrid. After its installation, you will see that previous code will not work. You need to change it a bit because types have been renamed. The new code will look very similar to the previous one:

using SendGrid.Helpers.Mail;
public static class SendThankYouEmailMessage
  public static void Run(
      To = "...",
      Subject = "...",
      Text = "...",
      From = "..."
    out SendGridMessage message)
    message = new SendGridMessage();

Together with that you should also add to applications settings two entries with the following name:

  • AzureWebJobsSendGridApiKey

and assign values provided by SendGrid.

At the end I would encourage you to see the previous article – Sending emails from Azure Functions v2 – SendGrid. You will find there a bigger description related to this integrations.