Azure runbook script to send mail using PowerShell and SendGrid

 Hi Friends,

Today I will be showing how to create and send the mail notification using the SendGrid through Azure Runbook and Powershell

Azure runbook script to send mail using PowerShell and SendGrid

SendGrid is a third party API that is very much integrated with Azure and is very easy to use. It provides various ways to send the mail. In this blog, I will be explaining the code to use SendGrid REST API to send the mail.


Step 1:

To use SendGrid, you should have 2 things
  1. SendGrid Subscription Key: This key will let the SendGrid know the subscription you have and will allow the number of emails accordingly
  2. Sender Identity: This identifies the sender so that the mails do not lands up in the SPAM/JUNK folder.
To have the above two, you need to login to the SendGrid and follow the instruction.

Step 2: Store the Subscription key in Key Vault

To maintain the security, I will be keeping the SendGrid Subscription Key into the Azure KeyVault. If you want to do the same, please follow the steps mentioned here

Make a note of the two properties that we will be needing in the script
  • Key Vault Name
  • Secret Name

Step 3: Code in Runbook

This is the last step, If you haven't created one follow the step below
  • Create an Automation Account
  • Navigate to the account and then to Runbooks and create a new one
Once the runbook is created, paste the below code and update the VaultName and SubscriptionKey variable values

Click on save and then test

Hope this script will save a lot of time and will help you... Do write me if you need any help on the topic.

Happy Coding..!!



Popular posts from this blog

Rename Folder using Microsoft Flow / Power Automate in a Document Library in SharePoint Online

Power Automate: How to Add "New Line" to the text in SharePoint multiline text field

Power Automate: Rename file in SharePoint Online