Leveraging Microsoft Flow As An Alternative For Sending Emails From Sharepoint

The Manual Burden of Sending Emails from SharePoint

The task of manually sending notification emails from SharePoint regarding content updates and changes places a repetitive administrative burden on employees. The manual process of crafting custom emails for each update eats up valuable time that could be better utilized for core business-focused activities.

Typically, employees receive alerts within SharePoint regarding important updates such as changes to documents, pages, or list items. But awareness often relies on employees proactively checking for these updates by logging into SharePoint and not necessarily being notified through more convenient communication channels.

The employee then must manually draft a new email detailing the SharePoint update, ascertain the relevant recipients that need this information, customize the messaging for that audience, and finally send out the notifications. This repetitive process results in lost productivity as sending manual alerts do not make effective use of employees with specialized skills.

Introducing Microsoft Flow for Automated Workflows

Microsoft Flow provides a robust automation platform to set up optimized workflows between Office 365 services and third-party apps. With Microsoft Flow, users can connect to SharePoint Online and automatically run flows when triggered by events within SharePoint.

For example, consider a common business scenario where documents in a specific SharePoint document library need review and sign-off. Previously, administrators had to manually detect when a new document requiring review was uploaded and then email the appropriate reviewers informing them of the task. With Microsoft Flow, this entire process can be automated by triggering customized email alerts as soon as new documents are added.

Microsoft Flow enables building flexible flows connecting business services through 300+ connectors. SharePoint can act as a trigger starting automated flows while email sending can be the resulting action. Workflows can even chain multiple actions, transforming content across apps and updating stakeholders.

Creating a Flow to Email SharePoint Updates

The following tutorial outlines how to create a Microsoft Flow triggered by SharePoint document library updates, which then sends automated emails regarding newly added documents needing review:

  1. Navigate to https://flow.microsoft.com and sign-in with user credentials having necessary SharePoint permissions

  2. Click on “Create” then select “Automated – Instant” flow

  3. For the trigger, search for “SharePoint” and select “When a file is created in a folder”

  4. Select the target SharePoint document library that requires notifications when updated

  5. Click on “+ New step” and search for “Send an email” action and add it

  6. Customize email recipients, subject, content using file metadata dynamic tokens

  7. Toggle advanced options to enable attachments, set importance level

  8. Turn flow toggle to “On” and save the automated workflow

Now, whenever a document gets added to the monitored SharePoint folder, the Microsoft Flow immediately sends an email with the file attached to the specified recipients saved within the notification template.

Additional Tips for Optimizing SharePoint Email Flows

The following best practices help create resilient, scalable flows for SharePoint update notifications:

  • Send email notifications in batch after set intervals instead of triggering on every update to avoid spam

  • Create apply-to-each loops for iterating through attachment array when emailing multiple files

  • Use initialize variable actions to process metadata like modified dates for dynamic content

  • Wrap Send Email actions under Scope control block to gracefully handle failures

  • Log emails sent data like timestamps, recipients to separate SharePoint lists for auditing

Properly structuring flows allows easily handling multiple file attachments, customize messages, implement robust error-handling as per business needs when integrating SharePoint and Office 365 email.

Example Flows and Code Snippets

The JSON definition showing the overall schema and actions for a sample SharePoint file uploader notification flow:

  {
    "definition": {
      "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
      "actions": {
        "Apply_to_each": {
           "type": "foreach",
           "actions": {
             "Send_email": {
               "inputs": {
                 "body": {
                    "Body": "@{items('Apply_to_each')?[''Name'']}, 
                    "Subject": "New document require review",
                    "To": "[email protected]" 
                  },
                  "host": {
                    "connection": {
                      "name": "@parameters('$connections')['office365']['connectionId']"
                    }
                  }
                },
                "runAfter": {},
                "type": "ApiConnection"
              }
            },
            "runAfter": {},
            "type": "Foreach"
          }
        }
      },
      "contentVersion": "1.0.0.0",
      "outputs": {},
      "parameters": {
        "$connections": {
          "defaultValue": {},
          "type": "Object"
        }
      },
      "triggers": {
        "When_a_file_is_created_in_a_folder": {
           "inputs": {
             "host": {
                "connection": {
                    "name": "@parameters('$connections')['sharepointonline']['connectionId']"
              }
             },
            "path": "/sites/team/documents/reviews",
            "rowLimit": 3
          },
          "recurrence": {
            "frequency": "Hour",
            "interval": 1
          },
          "splitOn": "@triggerBody()?[''value'']",
          "type": "ApiConnection"
        }
      }
    },
    "parameters": {
      "$connections": {
        "value": {
          "office365": {
            // REST API connection credentials
          },
          "sharepointonline": {
             // Username, password, site URL  
          }
        }
      }
    }
  }

To process metadata like file modification dates, initialize variable action snippets can be used:

  {
    "inputs": {
      "name": "fileModifiedDate",
      "type": "string",
      "value": "@triggerBody()?[''modified_date'']"
    },
    "runAfter": {},
    "type": "InitializeVariable"
  }

Custom logic apps connectors developed using C# and PowerShell simplify sending responses back to SharePoint after flow execution:


  // C# Azure Function app example 
  #r "Newtonsoft.Json"
  
  using System; 
  using Newtonsoft.Json;
  
  public static async Task Run(HttpRequestMessage req, IAsyncCollector output, TraceWriter log)
  {
    // Process logic app response

    output.Add(new {
      status = "success",
      updatedIds = updatedItems
    });
  }



  // PowerShell example 
  Param( 
    [string]$Request,
    [object]$TriggerMetadata
  )
  
  # Parse JSON inputs
  $expressionOutputs = $Request | ConvertFrom-Json
  
  # Output back to Logic App
  Push-OutputBinding -Name Response -Value {
    status = "success"
    fileIds = $expressionOutputs.body
  }

Leave a Reply

Your email address will not be published. Required fields are marked *