Click here to Skip to main content
15,883,901 members
Articles / DevOps
Tip/Trick

Send Email from Azure SQL using Logic App

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
24 Jan 2018CPOL4 min read 29.5K   4   2
How to send email from SQL Azure database through Azure PaaS services Logic Apps and SendGrid

Introduction

Notifications or emails shared to inform the end user about various information is a common feature requirement in any of the business application development. Sometimes, we may need to trigger the emails based on activities done in database. If we are using a IaaS or on-premise datacentre based database deployment, then we will be able to trigger the same using SMTP server configurations.

How can we trigger emails from Azure SQL or a PaaS service? We came across the requirement to trigger emails based on data updates in our Azure SQL and addressed the same using a combination of Logic apps and SendGrid. The procedure followed has been explained in this post.

SendGrid

The Azure Marketplace has the SendGrid email delivery service that can be utilized from Azure to send emails. It can be used from various web applications and services deployed in Azure PaaS.

Configuration Steps

There are four steps to accomplish this simple task:

  1. Configure the SendGrid
  2. Validate SendGrid settings
  3. Create table in Azure SQL Database
  4. Create Logic Apps

Configure the SendGrid

  1. Click on New from left upper corner in Azure Portal and type “SendGrid Email Delivery” in search box. It will show SendGrid Email Delivery resource as below:

    Image 1

  2. Click on Create button and it will open the below window.

    Image 2

  3. Provide the required details like name, password, subscription, resource group, etc. and click on Create button. For demo purposes, select Free tier in Pricing tier. It will allow you to send 25000 email/month.
  4. After confirming your purchase, you will see a Deployment Succeeded pop-up and you will see your account listed in the All resources section.
  5. You can find your SendGrid Email Delivery Service on your Azure subscription as below:

    Image 3

Validate SendGrid Settings

  1. Once you have created SendGrid Delivery Service, then clicked the Manage button from top menu to initiate the email verification process, you will receive an email from SendGrid asking you to verify your account.

    You can only send up to 100 emails/day until you have verified your account.

    To send an email using SendGrid, you must supply your API Key.

  2. Click on Manage button. It will open SendGrid dashboard site in new window as below:

    Image 4

  3. In your SendGrid dashboard, select Settings and then API Keys in the menu on the left.

    Image 5

  4. At a minimum, provide the Name of this key and provide full access to Mail Send and select Save.

Your API will be displayed at this point one time only. Please be sure to save it safely.

Create Sample Table in Azure SQL

Create one sample table in SQL Azure database. I am not going to explain this since it is a very straight forward step.

When we will create new record in this table, it will trigger Logic Apps which will eventually send email through SendGrid Email Delivery service that we will see in the next step.

Create Logic Apps

  1. Click on New on left upper corner on Azure Portal and enter text “Logic App” in Market place. It will show you Azure Logic App resource as below:

    Image 6

  2. Click on Create button. Then provide name, subscription, resource group, etc. required details and click on Create button in the below screen. It will create a new Logic App and will be available under your Resource Group.

    Image 7

  3. Newly created Logic App will display as below. Click on Edit:

    Image 8

  4. Now scroll down right side and select Logic App template from available different templates. For this example, we will select blank template of Logic App. It will show you as below:

    Image 9

  5. Now type “SQL Server” in connections and triggers textbox. It will show you SQL Server trigger as below. Select “SQL Server – when item is created” trigger.

    Image 10

  6. After select trigger, it will ask you to create SQL database connection, in which you just need to provide your SQL Azure credential and create SQL Connection with Logic Apps.
  7. Once SQL Connection has been established, it will populate the available SQL database tables in dropdown. You just select table name from drop down. Then specify time interval to check data insert in table. We have specified here default 3-minute time interval as below:

    Image 11

  8. Now click on “+ New step” box. It will show dialog box. Select Add an action from this dialog.

    Image 12

  9. Then type “SendGrid” in textbox. It will show you SendGrid Action list. Select “SendGrid – Send email(V2)“ option from window as below:

    Image 13

  10. It will provide you below window that provides details like from, To, Subject, Email body, etc. You need to create SendGrid connection from the below window:

    Image 14

  11. To create SendGrid connection, click on Connection. Provide connection name and SendGrid API Key which we stored in the earlier step.

    Image 15

  12. After creating connection, it will be ready to send email through SendGrid Email Delivery Service when new record is inserted in SQL Azure Table.

To test create new record in SQL Azure table, it will trigger Logic Apps and eventually send email through SendGrid email delivery service.

Conclusion

Orchestration of logic apps with integrations of existing apps like SendGrid will address lot of common integration issues with PaaS.

Points of Interest

Learn new concepts of Azure PaaS service while exploring new features of Azure.

History

  • 24th January, 2018: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer IT Company
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionMissing Authorization header for a privileged call on connection Pin
Member 409029120-Aug-20 4:51
Member 409029120-Aug-20 4:51 
QuestionCreating a table Pin
Teniel Gordon4-Sep-19 7:00
Teniel Gordon4-Sep-19 7:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.