Create an email subscription with Azure Functions - Part 1
Tags: azureapril, azure, webdev, tutorial
Published: 2019-04-10 13:59:53

---
title: Create an email subscription with Azure Functions - Part 1
published: true 
description: How to generate a weekly digest email for a blog using Azure functions, SendGrid and Azure Storage
tags: azureapril, azure, webdev, tutorial
series: Azure April
cover_image: https://thepracticaldev.s3.amazonaws.com/i/pblyvmtj4y8bdqisyzey.jpeg
---

*We've selected our favorite tips and tricks created by [Michael Crump](https://twitter.com/mbcrump) and are delivering fresh technical content on Azure all April! Miss a day (or more)? [Catch up with the series](https://dev.to/t/azureapril).*

**Don't have Azure?** [Grab a free subscription](https://azure.microsoft.com/en-us/free?&WT.mc_id=azureapril_devto-blog-cxa). 

This is the first post in a 4 part series on how to build a serverless email subscription service with [Azure Functions](https://azure.microsoft.com/services/functions/?WT.mc_id=azureapril_devto-blog-cxa).

![](https://thepracticaldev.s3.amazonaws.com/i/kcmscboecat39i9vk7ob.png)

We've all seen then before, and I must admit that I've never really looked into it before I started writing this Azure Tips and Tricks series.

We're all crazy busy, so it seems to be a good idea, for someone to give you an email address and be notified of new posts. OK, so I wanted to do it, and started looking into sites that offer this. After looking around, I kept finding this:

![](https://thepracticaldev.s3.amazonaws.com/i/oxpiymedaetihxuupxic.png)

Most companies offer you a certain number of subscribers for free, then you'll quickly get to a paid version once you go over that number.

Since I like to save a penny now and again and am aware that I have more subscribers than the free account offers (200), I decided to roll my own. But what would I need?

## My Requirements to roll my own
My requirements for my version of creating an email subscription is the following:

* A way to email folks for free or really, really cheap.
* Storage to save the email address and a way to indicate if they want to unsubscribe.
* A web page that folks can fill out that can make a POST call.
* Code running in the cloud (1) on a schedule and (2) perform actions based on a POST request.
* Visual Studio and C# as I'm well versed in them.

## My Stack
After poking around for a bit, I landed on the following:

* SendGrid will handle email (25K emails free monthly)
* Azure Storage Tables to save the email address and subscription status (this gives me an unlimited number of subscribers).
* Timer Trigger with Azure Functions to run on a schedule to send emails. (Runs weekly and retrieves my last 7 days worth of blog posts)
* HTTP Trigger with Azure Functions to collect POST data coming from my website that contains the email address and subscription status that someone types in.
* Azure Functions supports Visual Studio tooling and the full .NET Framework. (in case, I want to use something outside of .NET Core)

## Creating a SendGrid account
Go to the Azure Portal and search services for SendGrid and create an account as shown below. You'll notice that I used the Free account as it is good enough for what I was trying to accomplish.

![](https://thepracticaldev.s3.amazonaws.com/i/xnas0h1tjlxr0lrq0tpr.png)

Go to your SendGrid account once provisioned and click on Manage and it will bring you to https://app.sendgrid.com/. From the SendGrid portal, you are going to want to grab your API key. You can find it under Settings, then API Keys. Give your API Key a name and then give it Full Access and click Create and View. Now that you have your API Key, save it somewhere safe.

## Creating an Azure Storage Table
Go back to the Azure Portal and click Create a Resource and select Azure Storage. We'll keep it simple as shown below to get started.

![](https://thepracticaldev.s3.amazonaws.com/i/gc429qjg4p40ldufx4q9.png)

Once complete, go into the resource and look under Services.

![](https://thepracticaldev.s3.amazonaws.com/i/zcby6lo0hfq7mc49j9e0.png)

Go ahead and click on Tables and you could create a new table through the portal as shown below.

![](https://thepracticaldev.s3.amazonaws.com/i/lby3q5bxsgo51uhr6rco.png)

Go ahead and give the table a name that you'll remember and look under Settings, then Access Keys and copy the connection string as we'll use that shortly.

![](https://thepracticaldev.s3.amazonaws.com/i/o722tr3ttvrysnagktoh.png)

Now that we have our SendGrid account and our Azure Storage Table created. We can proceed.

## Open Visual Studio

Create a C# Azure Function application by opening Visual Studio and selecting the template under the Cloud node as shown below:

![](https://thepracticaldev.s3.amazonaws.com/i/637oxrzv7gglm9ga43ty.png)

Under Storage, change the default emulator to the Azure Storage Account that we created earlier:

![](https://thepracticaldev.s3.amazonaws.com/i/wu0wf5tp89riz8ldarj5.png)

We'll begin by using the Timer Trigger and leaving everything as the defaults.

![](https://thepracticaldev.s3.amazonaws.com/i/d4cgan69bl347md7elkt.png)

Once the project spins up, we'll use NuGet to pull in references to :

* WindowsAzure.Storage To work with Azure Table Storage.
* Microsoft.WindowsAzure.ConfigurationManager To hide our API keys
* Sendgrid To send our emails
* System.ServiceModel.Syndication To work with RSS feeds - use prerelease packages to find it

That's it for now! We'll do part two tomorrow

Want more Azure Functions? Check out our [quickstarts and tutorials](https://docs.microsoft.com/azure/azure-functions/?WT.mc_id=azureapril_devto-blog-cxa)!

---
We'll be posting articles every day in April, so stay tuned or jump ahead and check out more tips and tricks [now](http://azuredev.tips).