Creating SendGrid output binding to the Queue Trigger

  1. Navigate to the Integrate tab of the SendNotifications function and click on the New Output button to add a new output binding.
  2. Choose the SendGrid binding and click on the Select button to add the binding.
  3. The next step is to install the SendGrid extensions. Click on the Install button to install the extensions. It might take a few minutes to install them.
  4. Provide the following parameters in the SendGrid output (message) binding:
    • Message parameter name: Leave the default value, which is message. We will be using this parameter in the Run method in a moment.
    • SendGrid API Key: Choose the App settings key that you created in Application settings for storing the Send Grid API Key.
    • To address: Provide the email address of the administrator.
    • From address: Provide the email address where you would like to send the email from. It might be something like donotreply@example.com.
    • Message subject: Provide the subject that you would like to have displayed in the email subject.
    • Message Text: Provide the email body text that you would like to have in the email body.
  1. This is how the SendGrid output (message) binding should look like after providing all of the fields:
  1. Once you review the values, click on Save to save the changes.
  2. Navigate to the Run method of the SendNotifications function and make the following changes:
    • Add a new reference for SendGrid, along with the SendGrid.Helpers.Mail namespace.
    • Add a new out parameter message of the SendGridMessage type.
    • Create an object of the SendGridMessage type. We will look at how to use this object in the next recipe.
  3. The following is the complete code of the Run method:
#r "SendGrid"
using System;
using SendGrid.Helpers.Mail;

public static void Run(string myQueueItem,out SendGridMessage message, ILogger log)
{
log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
message = new SendGridMessage();
}

  1. Now, let's test the functionality of sending the email by navigating to the RegisterUser function and submitting a request with some test values, as follows:
        {
"firstname": "Bill",
"lastname": "Gates",
"ProfilePicUrl":"https://upload.wikimedia.org/
wikipedia/commons/thumb/1/19/
Bill_Gates_June_2015.jpg/220px-
Bill_Gates_June_2015.jpg"
}