Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Sendgrid through azure function
#r "SendGrid"
using System.Net;
using SendGrid.Helpers.Mail;
public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log, out Mail message)
log.Info("C# HTTP trigger function processed a request.");
// parse query parameter
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
// Get request body
dynamic data = req.Content.ReadAsAsync<object>().Result;
// Set name to query string or body data
name = name ?? data?.name;
message = new Mail();
message.Subject = "Someone passed a name to an azure function!";
var personalization = new Personalization();
personalization.AddTo(new Email(""));
Content content = new Content
Type = "text/plain",
Value =$"The name was {name}"
return name == null
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
: req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment