Sending Emails natively from Azure Data Factory or Synapse Pipelines

Patrick Pichler
Creative Data
Published in
2 min readOct 21, 2022

How to send emails programmatically via the Microsoft Graph API instead of relying on any other service like Azure Logic Apps

Photo by Campaign Creators on Unsplash

Introduction

The recommended and documented way to send emails from Azure Data Factory or Synapse Pipelines is using a Logic App workflow. While you can perfectly stick to this approach, you should bear in mind that this requires you to have another Azure resource including costs and also have parts of your business logic in different places making also version control a little bit more difficult. Further, it’s also quite inflexible when it comes to dynamically interacting with different (shared) mailboxes. Therefore, this article shows you a way to bypass these shortcomings by using the Microsoft Graph API together with Web Activity tasks to interact with the mailboxes directly.

Prerequisites

  1. Azure App registration with required Microsoft Graph Application Permissions, e.g. Mail.Send. Follow this article.

2. (Optional): Application Access Policy to limit Azure App registration to specific mailboxes otherwise it has access to any mailbox in an organization which might raise security concerns.

Pipeline Template

Once the Azure App is registered, you can make usage of this pipeline template. It consists of two tasks, one for retrieving a bearer token with the required scope and another one for sending the actual email by triggering a POST request.

You can integrate this pipeline into any of your existing pipelines and pass on certain parameters dynamically. For instance, by looping through a list of email senders and recipients.

Image by Author

Conclusion

In contrast to using Logic Apps, this is a very dynamic and reusable pattern for any Azure Data Factory or Synapse Pipeline which is also more integrated and hence easier to “version control”. Further, the Azure registration could be set up centrally with just a one-time effort and any pipeline can dynamically make usage of it.

--

--

Patrick Pichler
Creative Data

Promoting sustainable data and AI strategies through open data architectures.