How To Send Emails With Azure Twilio SendGrid

Introduction

Often while writing business logic we might come across scenarios where an application needs to send emails to customers, for example, to inform about the status of delivery in a shopping application, or to inform users about the status of the long running submitted jobs.

In such scenarios, often developers spend a lot of time trying to format the emails and send via SMTP server. This involves writing code to send emails which would become part of the application and any change in format or text needs redeployment and the entire CI CD pipe needs to run.

But there is SAAS Azure solution which can help to send emails and keep the logic of email templating outside the code.

Today I will show you how to create Twilio SendGrid login from Azure subscription.

Prerequisites

  1. Azure Subscription and basic Knowledge of Azure portal.
  2. C#, .net core and above Knowledge (samples are written in .net core)


Steps

  1. Login to Azure Portal and Search for TwilioSendgrid

    How to Send Emails with Azure Twilio SendGrid
     
  2. Twilio has many plans as shown below, but for demo purposes, I'll select the free plan.

  3. Select the subscription and resource group.


     
  4. Finally review the configurations you have done


     
  5. After the resource is created, navigate to the resource and click on “Open SAAS Account on publisher site”


     
  6. The above step will take you to app.sendgrid.com, where the account is already logged-in.

    The first step here is to create and verify the sender identity

    How to Send Emails with Azure Twilio SendGrid

    There is step by step guide to achieve this using the documentation provided on website
     
  7. Once completed you can explore the website. The next step is to create the API Keys to use in the Application which can be created by click on the user name on the left side.


     
  8. Create the API keys as shown below

    How to Send Emails with Azure Twilio SendGrid
     
  9. Once you have the API Keys this can be used in your application to send Emails.

There is a nugget package available called “SendGrid” which can be used to send emails. I have written a small code to send email using the API keys, sender email ID and name of the sender.
https://github.com/santoshkaranam/MailWithAzureTwilioSendGrid

References

  1. https://docs.sendgrid.com/for-developers/partners/microsoft-azure-2021
  2. https://sendgrid.com/partners/azure/
Next Recommended Reading Send Mail Using SendGrid