Emailing via Azure in .NET Core 2.0

Problem

How to send emails in .NET Core using Azure SendGrid service.

Solution

Create a class library and add NuGet package:  Sendgrid

Add a class to encapsulate settings and server response:

Add a class to encapsulate an email message (see also the previous post on builder pattern):

Add a class to wrap functionality of sending email messages:

To use the above class:

Note: the sample code includes the builder for email message

Discussion

The sample code will require you to setup Azure account and SendGrid account. Instructions for these could be found at: https://docs.microsoft.com/en-us/azure/app-service-web/sendgrid-dotnet-how-to-send-email#create-a-sendgrid-account

You’ll also need API Key, which can be created at: https://app.sendgrid.com/ using your Azure SendGrid username and password. More details can be found at: https://sendgrid.com/docs/Classroom/Send/How_Emails_Are_Sent/api_keys.html

Source Code

GitHub: https://github.com/TahirNaushad/Fiver.Azure.Email

Leave a Reply