Skip to content

Commit 8e5a7ca

Browse files
authored
Merge pull request #174839 from jonburchel/2021-10-06-how-to-send-email-article
Simple How-To showing how to send email with pipeline from Logic App
2 parents dfcc4b9 + 2ae82f3 commit 8e5a7ca

11 files changed

+126
-3
lines changed

articles/data-factory/TOC.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,8 @@ items:
737737
href: monitor-install-analytics.md
738738
- name: Monitor with SDKs
739739
href: monitor-programmatically.md
740+
- name: Monitor pipelines with email notifications
741+
href: how-to-send-email.md
740742
- name: Monitor pipelines with Microsoft Teams notifications
741743
href: how-to-send-notifications-to-teams.md
742744
- name: Monitor integration runtime
@@ -875,8 +877,10 @@ items:
875877
- name: Discover and explore data in ADF using Purview
876878
href: how-to-discover-explore-purview-data.md
877879
- name: Scenarios
878-
items:
879-
- name: Monitor pipelines with Microsoft Teams notifications
880+
items:
881+
- name: Send email from a pipeline
882+
href: how-to-send-email.md
883+
- name: Send Microsoft Teams notifications from a pipeline
880884
href: how-to-send-notifications-to-teams.md
881885
- name: Data migration for data lake & EDW
882886
items:
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
title: How to send email
3+
titleSuffix: Azure Data Factory & Azure Synapse
4+
description: Learn how to send an email with an Azure Data Factory or Azure Synapse pipeline.
5+
author: ssabat
6+
ms.author: susabat
7+
ms.reviewer: jburchel
8+
ms.service: data-factory
9+
ms.subservice: tutorials
10+
ms.topic: tutorial
11+
ms.date: 06/07/2021
12+
---
13+
14+
# Send an email with an Azure Data Factory or Azure Synapse pipeline
15+
16+
[!INCLUDE[appliesto-adf-asa-md](includes/appliesto-adf-asa-md.md)]
17+
18+
It's often necessary to send notifications during or after execution of a pipeline. Notification provides proactive alerting and reduces the need for reactive monitoring to discover issues.  This article shows how to configure email notifications from an Azure Data Factory or Azure Synapse pipeline. 
19+
20+
## Prerequisites
21+
22+
- **Azure subscription**. If you don't have an Azure subscription, create a [free](https://azure.microsoft.com/free/) account before you begin.
23+
- **Logic App**. To trigger sending an email from the pipeline, you use [Logic Apps](../logic-apps/logic-apps-overview.md) to define the workflow. For details on creating a Logic App workflow, see [How to create a logic app](../logic-apps/quickstart-create-first-logic-app-workflow.md).
24+
25+
## Create the email workflow in your Logic App
26+
27+
Create a Logic App workflow named `SendEmailFromPipeline`. Define the workflow trigger as `When an HTTP request is received`, and add an action of `Office 365 Outlook – Send an email (V2)`.
28+
29+
:::image type="content" source="media/how-to-send-email/logic-app-workflow-designer.png" alt-text="Shows the Logic App workflow designer with a Send Email (V2); action from an HTTP request trigger.":::
30+
31+
For the HTTP request trigger, provide this JSON for the `Request Body JSON Schema`:
32+
33+
```json
34+
{
35+
"properties": {
36+
"dataFactoryName": {
37+
"type": "string"
38+
},
39+
"message": {
40+
"type": "string"
41+
},
42+
"pipelineName": {
43+
"type": "string"
44+
},
45+
"receiver": {
46+
"type": "string"
47+
}
48+
},
49+
"type": "object"
50+
}
51+
```
52+
53+
The HTTP Request in the Logic App Designer should look like this:
54+
55+
:::image type="content" source="media/how-to-send-email/logic-app-http-request-trigger.png" alt-text="Shows the Logic App workflow designer for the HTTP Request trigger with the Request Body JSON Schema field populated.":::
56+
57+
For the **Send Email (V2)** action, customize how you wish to format the email, using the properties from the request Body JSON schema:
58+
59+
:::image type="content" source="media/how-to-send-email/logic-app-email-action.png" alt-text="Shows the Logic App workflow designer for the Send Email (V2) action.":::
60+
61+
Save the workflow. Make a note of the Workflow URL for your new workflow then:
62+
63+
:::image type="content" source="media/how-to-send-email/logic-app-workflow-url.png" alt-text="Shows the Logic App workflow Overview tab with the Workflow URL highlighted.":::
64+
65+
## Create a pipeline to trigger your Logic App email workflow
66+
67+
Once you create the Logic App workflow to send email, you can trigger it from a pipeline using a **Web** activity.
68+
69+
1. Create a new pipeline and find the **Web** activity under the **General** category, to drag it onto the editing canvas.
70+
71+
1. Select the new **Web1** activity, and then select the **Settings** tab.
72+
73+
Provide the URL from the Logic App workflow you created previously in the **URL** field.
74+
75+
Provide the following JSON for the **Body**:
76+
```json
77+
{
78+
"message" : "This is a custom dynamic message from your pipeline with run ID @{pipeline().RunId}.",
79+
"dataFactoryName" : "@{pipeline().DataFactory}",
80+
"pipelineName" : "@{pipeline().Pipeline}",
81+
"receiver" : "@{pipeline().parameters.receiver}"
82+
}
83+
```
84+
85+
Use dynamic expressions to generate useful messages for events in your pipelines. Notice that the JSON format here matches the JSON format you defined in the Logic App, and you can also customize these as required.
86+
87+
:::image type="content" source="media/how-to-send-email/pipeline-with-web-activity-calling-logic-app.png" alt-text="Shows a pipeline with a Web activity configured with the Logic App workflow URL and JSON message body.":::
88+
89+
1. Select the background area of the pipeline designer to select the pipeline properties page and add a new parameter called receiver, providing an email address as its Default value.
90+
91+
In this example, we provide the receiver email from a pipeline parameter we define arbitrarily. The receiver value could be taken from any expression, or even linked data sources.
92+
93+
:::image type="content" source="media/how-to-send-email/pipeline-receiver-email-parameter.png" alt-text="Shows the configuration of the receiver parameter in the pipeline designer.":::
94+
95+
1. Publish your pipeline, and then trigger it manually to confirm the email is sent as expected.
96+
97+
:::image type="content" source="media/how-to-send-email/pipeline-manually-trigger.png" alt-text="Shows how to manually trigger the pipeline.":::
98+
99+
## Add dynamic messages with system variables and expressions
100+
101+
You can use [system variables](control-flow-system-variables.md) and [expressions](control-flow-expression-language-functions.md) to
102+
make your messages dynamic. For example:  
103+
104+
- ``@activity("CopyData").output.errors[0].Message``
105+
106+
- ``@activity("DataFlow").error.Message``
107+
108+
The above expressions will return the relevant error messages from a Copy activity failure. Refer to the
109+
[Copy activity output properties](copy-activity-monitoring.md) article for more details.
110+
111+
## Next Steps
112+
113+
[How to send Teams notifications from a pipeline](how-to-send-notifications-to-teams.md)

articles/data-factory/how-to-send-notifications-to-teams.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,7 @@ The above expressions will return the relevant error messages from a failure, wh
106106

107107
We also encourage you to review the Microsoft Teams supported [notification payload schema](https://adaptivecards.io/explorer/AdaptiveCard.html) and
108108
further customize the above template to your needs.
109+
110+
## Next Steps
111+
112+
[How to send email from a pipeline](how-to-send-email.md)
37.6 KB
Loading
41 KB
Loading
35.8 KB
Loading
50.9 KB
Loading
51.7 KB
Loading
47.6 KB
Loading
77.3 KB
Loading

0 commit comments

Comments
 (0)