Reader small image

You're reading from  Azure Serverless Computing Cookbook. - Third Edition

Product typeBook
Published inJun 2020
PublisherPackt
ISBN-139781800206601
Edition3rd Edition
Concepts
Right arrow
Author (1)
Praveen Kumar Sreeram
Praveen Kumar Sreeram
author image
Praveen Kumar Sreeram

Praveen Kumar Sreeram is an author, Microsoft Certified Trainer, and certified Azure Solutions Architect. He has over 15 years of experience in the field of development, analysis, design, and the delivery of applications of various technologies. His projects range from custom web development using ASP.NET and MVC to building mobile apps using the cross-platform Xamarin technology for domains such as insurance, telecom, and wireless expense management. He has been given the Most Valuable Professional award twice by one of the leading social community websites, CSharpCorner, for his contributions to the Microsoft Azure community through his articles. Praveen is highly focused on learning about technology, and blogs about his learning regularly. You can also follow him on Twitter at @PrawinSreeram. Currently, his focus is on analyzing business problems and providing technical solutions for various projects related to Microsoft Azure and .NET Core.
Read more about Praveen Kumar Sreeram

Right arrow

2. Working with notifications using the SendGrid and Twilio services

In this chapter, we will look at the following:

  • Sending an email notification using SendGrid service
  • Sending an email notification dynamically to the end user
  • Implementing email logging in Azure Blob Storage
  • Modifying the email content to include an attachment
  • Sending an SMS notification to the end user using the Twilio service

Introduction

One of the key features required for the smooth running of business applications is to have a reliable communication system between the business and its customers. The communication channel usually operates two-way, by either sending a message to the administrators managing the application or by sending alerts to customers via emails or SMS to their mobile phones.

Azure can integrate with two popular communication services: SendGrid for emails, and Twilio for working with text messages. In this chapter, we will learn how to leverage both of these communication services to send messages between business administrators and end users.

Figure 2.1 is the architecture that we will be using for utilizing SendGrid and Twilio Output Bindings with HTTP and queue triggers:

  1. Client applications (web/mobile) make Http Requests, which trigger the Http Trigger.
  2. The Http Trigger creates a message to the Queue.
  3. A Queue Trigger is invoked as soon as a message arrives...

Sending an email notification using SendGrid service

In this recipe, we will learn how to create a SendGrid output binding and send an email notification, containing static content, to the website administrator. Since our use case involves just one administrator, we will be hard-coding the email address of the administrator in the To address field of the SendGrid output (message) binding.

Getting ready

We'll perform the following steps before moving on to the next section:

  1. We will create a SendGrid account API key from the Azure portal.
  2. We will generate an API key from the SendGrid portal.
  3. We will configure the SendGrid API key with the Azure Function app.

Creating a SendGrid account API key from the Azure portal

In this section, we'll be creating a Send service and also generate the API by performing the following steps:

  1. Navigate to the Azure portal and create a SendGrid Email Delivery account by searching for it in the marketplace...

Sending an email notification dynamically to the end user

In the previous recipe, we hard-coded most of the attributes related to sending an email to an administrator as there was just one administrator. In this recipe, we will modify the previous recipe to send a Thank you for registration email to the users themselves.

Getting ready

Make sure that the following steps are configured properly:

  • The SendGrid account is created and an API key is generated in the SendGrid portal.
  • An App settings configuration is created in the configuration of the function app.
  • The App settings key is configured in the SendGrid output (message) bindings.

How to do it…

In this recipe, we will update the code in the run.csx file of the following Azure functions:

  • RegisterUser
  • SendNotifications

Accepting the new email parameter in the RegisterUser function

Let's make changes to the RegisterUser function to accept the email parameter by performing...

Implementing email logging in Azure Blob Storage

Most of the business applications for automated emails are likely to involve sending emails containing various notifications and alerts to the end user. At times, it is not uncommon for users to not receive any emails, even though we, as developers, don't see any error in the application while sending such notification alerts.

There might be multiple reasons why such users might not have received the email. Each of the email service providers has different spam filters that can block the emails from the end user's inbox. As these emails may have important information to convey, it makes sense to store the email content of all the emails that are sent to the end users, so that we can retrieve the data at a later stage for troubleshooting any unforeseen issues.

In this recipe, you will learn how to create a new email log file with the .log extension for each new registration. This log file can be used as redundancy for...

Modifying the email content to include an attachment

In this recipe, you will learn how to send a file as an attachment to the registered user. In our previous recipe, we created a log file of the email content, which we will use as an email attachment for this instance. However, in real-world applications, you might not intend to send log files to the end user.

Note

At the time of writing, SendGrid recommends that the size of the attachment shouldn't exceed 10 MB, though technically, your email can be as large as 20 MB.

Getting ready

This is a continuation of the Implementing email logging in Azure Blob Storage recipe. If you are reading this first, make sure to go through the previous recipes of this chapter beforehand.

How to do it...

In this section, we will need to perform the following steps before moving to the next section:

  1. Make the changes to the code to create a log file with the RowKey of the table. We will achieve this using the IBinder...

Sending an SMS notification to the end user using the Twilio service

In most of the previous recipes of this chapter, we have worked with SendGrid triggers to send emails in different scenarios. In this recipe, you will learn how to send notifications via text messages, using one of the leading cloud communication platforms, named Twilio.

Note

Twilio is a cloud communication platform-as-a-service platform. Twilio allows software developers to programmatically make and receive phone calls, send and receive text messages, and perform other communication functions using its web service APIs. Learn more about Twilio at https://www.twilio.com/.

Getting ready

In order to use the Twilio SMS output (objsmsmessage) binding, you need to do the following:

  1. Create a trial Twilio account at https://www.twilio.com/try-twilio.
  2. Following the successful creation of the account, grab the ACCOUNT SID and AUTH TOKEN from the Twilio Dashboard and save it for future reference, as...
You have been reading a chapter from
Azure Serverless Computing Cookbook. - Third Edition
Published in: Jun 2020Publisher: PacktISBN-13: 9781800206601
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Praveen Kumar Sreeram

Praveen Kumar Sreeram is an author, Microsoft Certified Trainer, and certified Azure Solutions Architect. He has over 15 years of experience in the field of development, analysis, design, and the delivery of applications of various technologies. His projects range from custom web development using ASP.NET and MVC to building mobile apps using the cross-platform Xamarin technology for domains such as insurance, telecom, and wireless expense management. He has been given the Most Valuable Professional award twice by one of the leading social community websites, CSharpCorner, for his contributions to the Microsoft Azure community through his articles. Praveen is highly focused on learning about technology, and blogs about his learning regularly. You can also follow him on Twitter at @PrawinSreeram. Currently, his focus is on analyzing business problems and providing technical solutions for various projects related to Microsoft Azure and .NET Core.
Read more about Praveen Kumar Sreeram