




















































SendGrid is one of the popular services that allow the audience to send emails for different purposes. In today’s tutorial we will explore to:
Here, we will learn how to create a SendGrid output binding and send an email notification to the administrator with a static content. In general there would be only administrators so we will be hard coding the email address of the administrator in the To address field of the SendGrid output binding
#r "Microsoft.WindowsAzure.Storage"
#r "SendGrid"
using System.Net;
using SendGrid.Helpers.Mail;
using Microsoft.WindowsAzure.Storage.Table;
using Newtonsoft.Json;
public static void Run(HttpRequestMessage req, TraceWriter log,
CloudTable objUserProfileTable,
out string objUserProfileQueueItem,
out Mail message
)
{
var inputs = req.Content.ReadAsStringAsync().Result;
dynamic inputJson = JsonConvert.DeserializeObject<dynamic>(inputs);
string firstname= inputJson.firstname;
string lastname=inputJson.lastname;
string profilePicUrl = inputJson.ProfilePicUrl;
objUserProfileQueueItem = profilePicUrl;
UserProfile objUserProfile = new UserProfile(firstname, lastname); TableOperation objTblOperationInsert =
TableOperation.Insert(objUserProfile);
objUserProfileTable.Execute(objTblOperationInsert);
message = new Mail();
}
public class UserProfile : TableEntity
{
public UserProfile(string lastName, string firstname,string profilePicUrl)
{
this.PartitionKey = "p1";
this.RowKey = Guid.NewGuid().ToString();;
this.FirstName = firstName; this.LastName = lastName; this.ProfilePicUrl = profilePicUrl;
}
public UserProfile() { }
public string FirstName { get; set; } public string LastName { get; set; } public string ProfilePicUrl {get; set;}
}
{
"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"
}
The aim here is to send a notification via email to an administrator updating that a new registration got created successfully.
We have used the one of the Azure Function experimental templates named SendGrid as a SMTP server for sending the emails by hard coding the following properties in the SendGrid output bindings:
SendGrid output bindings will use the API key provided in the app settings to invoke the required APIs of the SendGrid library for sending the emails.
To summarize, we learnt about sending an email notification using SendGrid service.
[box type="shadow" align="" class="" width=""]This article is an excerpt from the book, Azure Serverless Computing Cookbook, written by Praveen Kumar Sriram. It contains over 50 recipes to help you build applications hosted on Serverless architecture using Azure Functions.[/box]
5 reasons why your business should adopt cloud computing
Alibaba Cloud partners with SAP to provide a versatile, one-stop cloud computing environment
Top 10 IT certifications for cloud and networking professionals in 2018