Send alerts to Microsoft Teams and email alerts about unsent and failed emails

Published January 23, 2025
Modules
Difficulty
Selected Clients
empik logo

Effective communication is crucial for maintaining strong relationships with customers and ensuring seamless business operations. In scenarios in which message delivery issues occur, such as unsent and failed messages, these disruptions can impact customer satisfaction and operational efficiency.

This use case focuses on implementing a comprehensive monitoring and alert system for unsent and failed messages. By using Synerise’s the Automation module, businesses can distribute detailed daily reports and set up real-time alerts to notify channel members in Microsoft Teams and send email alerts when message delivery issues occur. This proactive approach helps maintain communication reliability and enhances customer satisfaction. In our case we will start this automation daily to check the number of message.notSent events and the list of possible errors. The message alert will be sent only if the number of unsent messages will be higher or equal to 1.

Note: This case specifically describes creating reports based on the message.notSent event, which is generated when the process of sending an email fails. However, it can be easily adapted by incorporating additional events that are generated when delivery issues occur in different communication channels. For instance, events like push.notSent or webpush.notSent can be included to ensure a broader scope of monitoring.

Prerequisites


Create a workflow from a channel in Teams by following steps below:

  1. Go to Power Automate to create a workflow from a channel in Teams. Save workflow to generate incoming webhook URL.
  2. Edit the created workflow by filling out the TeamId and ChannelId fields. These values will be suggested. If not:
    • To get the value of TeamId, go to the MS Teams application and retrieve a link to the team. TeamId is the part of generated URL groupId=XXXX.
    • To get the value of ChannelId, go to the MS Teams application and retrieve a link to the channel. ChannelId is a part of generated URL channel/XXXXXXXX.
  3. Save the changes in the workflow.
  4. If you want to send an interactive message (such message can contain links, simple surveys, sections), prepare it in AdaptiveCard.

Process


In this use case, you will go through the following steps:

  1. Create a metric which counts the occurrences of message.notSent events.
  2. Create a report.
  3. Create an email template that contains description of error parameters.
  4. Create a workflow which sends an email alert.
  5. Create a workflow which sends the message to the Microsoft Teams channel.

Create a metric


In this part of the process, we will create a metric whose result will be later sent in the Microsoft Teams message. This specific metric will count the number of unsent email messages.

  1. In Synerise, go to Analytics icon Analytics > Metrics > New metric.
  2. Enter the name of the metric.
  3. As the metric type, choose Simple metric.
  4. From the Type dropdown, choose Event.
  5. As an aggregator, choose Count.
  6. From the Choose event dropdown list, select message.notSent.
  7. Set the time range to Yesterday.
The configuration of the metric
The configuration of the metric

Create a report


In this part of the process, we will create a report whose results will be later sent in the Microsoft Teams message.

  1. Go to Analytics icon Analytics > Reports > New report.

  2. Enter a meaningful name of the report.

  3. From the Choose metric dropdown list, select a metric created in “Create a metric” part of the process.

  4. From the Range dropdown list, select the number. This number should be linked to the average number of campaigns sent daily and may therefore be smaller or larger depending on the business. In this case it will be TOP 20.

  5. In the Dimension section, from the dropdown list, select Event > Parameters. From the list, select the following parameters:

    • campaignName
    • info
    • extra
    • exception
    • id
    • diagramId
    Note:
    • You can find descriptions of these parameters in the documentation for the message.notSent event.
    • If needed, you can add more parameters, reduce its number, or modify them to suit your specific business requirements.
  6. Choose Show null values.

  7. Using the date picker in the lower-right corner, set the time range to Yesterday.

  8. Save the report.

The configuration of the report
The configuration of the report

Create an email template


You can use a ready-made template (available on the Synerise Demo workspace) that inserts the data you want to send in a table format.

  1. On the right panel, click the Config tab.

  2. Fill out Title and Subtitle to personalize the header and subtitle in the template.

  3. Define Maximum report table rows number.

  4. In Report id, enter the ID of the report you created within “Create a report”.
    You can retrieve the report ID by going to Analytics > Reports. On the list of reports, find the report you created in the previous part of the process. To the right side of the report author, expand the context menu and at the bottom of the list, copy the ID.

  5. In the General Settings section:

    • From the Synerise environment dropdown, select the cloud where your workspace is hosted.
    • From the Campaign type dropdown, select email.
  6. Click Save as.

  7. On the pop-up, you can change the name and select the folder where the template will be saved.

    Email notification on email performance template
    The configuration of the email template

Create a workflow


In this part of the process, you will create a workflow that sends a message with the report results through email once a day. The message alert will be sent only if the number of unsent messages will be higher than 1.

  1. In Synerise, go to Automation > Workflows > New workflow.
  2. Enter the name of the workflow.

Define the Scheduled Run trigger node


At this stage, configure the conditions that trigger the workflow.

  1. As the trigger node, select Scheduled Run.
  2. In the configuration of the node:
    1. Change the Run trigger option to all time.
    2. Choose the Everyday option.
    3. Choose the timezone and hour (in our case, it’s 6.00 A.M.)
    4. Confirm by clicking Apply.
The configuration of the Scheduled Run node
The configuration of the Scheduled Run node

Choose Get Analytics Report Node


  1. Choose Get Analytics Report.
  2. From the dropdown list, select the report created in “Create a report” part of the process.
  3. Set report records limit.
  4. Click Apply.
The configuration of the Get Analytics Report Node
The configuration of the Get Analytics Report Node

Define the Metric Filter node


In the Metric Filter node, you will select the metric prepared in “Create a metric” part of the process. The continuation of the workflow will depend on the result of the metric. If the metric result is equal to or more than 1, an alert will be sent.

  1. Add Metric Filter.
  2. In Define condition, choose the metric created in the previous step.
  3. As the condition, by using the mathematical operators, set the metric result as equal or more than 1.
  4. Click Apply.
The configuration of the Metric Filter node
The configuration of the Metric Filter node

Define the Email Alert Node


  1. Add the Email Alert node to the matched path. In the configuration of the node:
    1. In the Content section, select the email template created in the previous step and in the Subject field, enter your message subject.
    2. In the Recipient section, use the text field to add at least one email address of a workspace user to whom the message will be sent.
    3. Confirm the selection by clicking Add.
    4. Confirm by clicking Apply.

Add the finishing node


  1. Add the End node:
    • To the Not matched path,
    • After the Email Alert node.
  2. In the upper right corner, click Save & Run.
Data Reference Workflow
Workflow configuration

Create a workflow sending Teams alert


In this part of the process, you will create a workflow that sends a message to the Microsoft Teams channel once a day. The workflow will look similar to one created previously but instead of the Email Alert node, we use the Send Channel Message node. Its settings are described below.

Send channel message


In this step, you will configure the settings of the outgoing integration that sends the alert message to Microsoft Teams channel.

  1. Add the Send Channel message node.
  2. In the configuration of the node:
    • If you already created a connection, select the connection from the list.
    • If you haven’t created any connection yet:
    1. At the bottom of the dropdown list, click Add connection.
    2. In the Incoming Webhook URL field, enter the incoming webhook URL you created as a part of prerequisites.
    3. Click Next.
    4. In the Connection name field, enter the name for the connection you created.
    5. Click Apply.
      Result: A connection is created and selected.
  3. In the Type of message field, choose Interactive message (JSON).
  4. Below, in JSON body, add the content of the message which will be sent to the Microsoft Teams channel.
Note:

In the code below, remember to replace a few things:

  • set mentions: Replace email addresses with emails of workspace users who are supposed to be mentioned on the Teams channel when a new report is available.
  • set reportId: Set this to the ID of the report created in “Create a report”.
  • set env: Replace this with the environment your workspace is hosted.
  • set campaignType: Replace this with the type of campaign, in our case: email.
Click to expand the code

 {#CONFIG#}
 {% set mentions = ['abc@synerise.com','xyz@synerise.com']%} {# you can leave array empty []#}
 {% set title = "Message.notSent alert" %}
 {% set reportId = 'f3370785-f309-4b6f-b47f-bb10de377708' %}
 {% set env = 'microsoft' %} {# microsoft, google #}
 {% set campaignType = 'email' %} {# email, sms, mobile-push, webpush #}
 {#ENDCONFIG#}

 {% set baseUrl = 'https://app.geb.synerise.com' if env == 'google' else 'https://app.synerise.com' %}
 {
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "type": "AdaptiveCard",
    "version": "1.4",
    "body": [
        {
            "type": "TextBlock",
            "text": "{% for mention in mentions %}<at>{{mention}}</at>{% if not loop.last %}, {% endif %}{% endfor %}",
            "size": "small"
        },
        {
            "type": "TextBlock",
            "size": "Medium",
            "weight": "Bolder",
            "text": "{{title}}"
        },
        {
            "type": "Table",
            "columns": [
                {
                    "width": 1
                },
                {
                    "width": 1
                },
                {
                    "width": 1
                },
                {
                    "width": 1
                },
                {
                    "width": 1
                }
            ],
            "rows": 
            {% set dataRow=[] %}

            {% set titles=['campaignName', 'info', 'extra', 'value', 'campaignId'] %}
            {% set cells = []  %}
            {% for t in titles %}
            {% do cells.append(
                {
                    "type": "TableCell",
                    "items": 
                    [
                        {
                            "type": "TextBlock",
                            "text": t,
                            "wrap": true
                        } 
                    ]
                }
            ) %}
            {% endfor %}
            {% do dataRow.append({"type": "TableRow","cells":cells}) %}

            {% datareference node='Get report' maxRows=12 %}
            {% set cells=[] %}
            {% for r in datareference_result %}
            {% set cells=[
                    {
                        "type": "TableCell",
                        "items": 
                        [
                            {
                                "type": "TextBlock",
                                "text": r.campaignName +' [[link]]('+baseUrl+'/campaigns/'+campaignType+'/preview/'+r.id+')',
                                "wrap": true
                            }
                            ,
                            {
                                "type": "TextBlock",
                                "text": 'Automation [[link]]('+baseUrl+'/automations/workflows/automation-diagram/'+r.diagramId+')' if r.diagramId is not string_containing 'null' else '',
                                "wrap": true
                            }
                        ]
                    },
                    {
                        "type": "TableCell",
                        "items": 
                        [
                            {
                                "type": "TextBlock",
                                "text": r.info,
                                "wrap": true
                            }
                        ]
                    },
                    {
                        "type": "TableCell",
                        "items": 
                        [
                            {
                                "type": "TextBlock",
                                "text": r.extra,
                                "wrap": true
                            }
                        ]
                    },
                    {
                        "type": "TableCell",
                        "items": 
                        [
                            {
                                "type": "TextBlock",
                                "text": r.Value|int,
                                "wrap": true
                            }
                        ]
                    },
                    {
                        "type": "TableCell",
                        "items": 
                        [
                            {
                                "type": "TextBlock",
                                "text": r.id,
                                "wrap": true
                            }
                        ]
                    }
                ]%}
            {% do dataRow.append({"type": "TableRow","cells":cells}) %}
            
            {% endfor %}
            {% enddatareference %}
            {{dataRow|tojson}}
            
        }
    ],
    "actions": [
        {
            "type": "Action.OpenUrl",
            "title": "Raport",
            "url": "{{baseUrl}}/analytics/reports/{{reportId}}"
        }
    ],
    "bleed": true,
    "msteams": {
        "width": "Full",
        "entities": [
            {% for mention in mentions %}
            {
                "type": "mention",
                "text": "<at>{{mention}}</at>",
                "mentioned": {
                    "name": "{{mention}}",
                    "id": "{{mention}}"
                }
            }
            {% if not loop.last %}
            ,
            {% endif %}
            {% endfor %}
        ]
    }
} 
  

Important: Remember, that the rest of the code and the adaptive card are designed to match the parameters of the event described earlier. The results of this report will reflect those parameters. If you want to show fewer, additional, or different parameters, you will need to modify the rest of the code accordingly.
  1. Confirm by clicking Apply.
Configuration of the workflow that sends alert messages based on the metric results to the Teams channel
Configuration of the workflow that sends alert messages based on the metric results to the Teams channel

Add the finishing node


  1. Add the End node after Send channel message and to the not matched path.
  2. In the upper right corner, click Save & Run.
Data Reference Workflow
Workflow configuration

Check the use case set up on the Synerise Demo workspace


Directly in our Synerise Demo workspace, you can check the configuration of:

If you don’t have access to the Synerise Demo workspace, please leave your contact details in this form, and our representative will contact you shortly.

Read more


😕

We are sorry to hear that

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

😉

Awesome!

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

Close modal icon Placeholder alt for modal to satisfy link checker