How to send Emails with SendGrid in ADO Pipeline?
What is SendGrid?
SendGrid is a SaaS email service or delivery tool that helps send emails. We can consider SendGrid as an SMTP server. SendGrid is free for emails up to 100/day. Sendgrid is used for personal as well as Business as well but for our demo today I have used my personal account.
To open your account in SendGrid just sign up on this website https://app.sendgrid.com and create an API key. We have not covered in detail how to create API for SendGrid that you can google and get it easily.
ADO and SendGrid Integration
Although SendGrid is a third-party tool, ADO provides a marketplace for available extensions to integrate and use into the pipeline. Once you have set up your SendGrid account, use the below link to add the SendGrid tool to Azure Pipeline tasks.
https://marketplace.visualstudio.com/items?itemName=kasunkodagoda.sendgrid-email
Once you click the “Get It Free” button, Select your DevOps organization from the dropdown and click on the Install button.
After adding the SendGrid tool in ADO, you would able to see the SendGrid task in Azure Pipeline as shown below.
Click on the SendGrid Email task and you see the below parameters to fill it.
Provide the proper details above. Make sure the Sender’s Email Address is the configured email account on the SendGrid portal and the recipient’s email can be any existing one.
See the Pipeline code below for the SendGrid.
trigger:
- None
pool:
vmImage: ubuntu-latest
steps:
- task: SendGridEmail@2
inputs:
SendGridApiKey: 'SG.###############################################'
FromAddress: 'chiragce17@gmail.com'
ToAddresses: 'chiragnagrekar@hotmail.com'
Subject: 'Test SendGrid Account'
emailBodyFormat: 'InLine'
EmailBody: 'Test SendGrid Email Functionality'
For the security reasons you can make all items parameterize or at least SendGrid API key as a sensitive parameter value.