Outlook: Outlook integration with SharePoint using Microsoft Flow

Introduction

We are going to integrate outlook with SharePoint. We will automatically move the email attachment from an email to SharePoint library. We will use MS Flow for this integration.

We apply the MS Flow on a specific email account. Flow start as soon as you receive new email. Flow can retrieve the email subject, body, attachment, From email id and To email id.  We are going to verify the email subject. If it matches with the predefined subject then it will automatically move email attachment from outlook email to SharePoint library. i.e. If we would like to move all the invoices into SharePoint. We can try to find invoice keyword in a subject and email body. If-Match found it’ll get that Mail’s Attached Document and creates a new File into the SharePoint Document Library.

We are going to develop the Invoice Management process in Office 365 SharePoint, Outlook and Microsoft Flow. We are going to move invoice attachment from outlook to SharePoint library.

Working Procedure

Flow runs when an email arrives into the Office 365 outlook inbox. There is a two steps verification to identify the invoice email.

Step 1: Search for Invoice keyword into the subject of the mail if match found it’ll get the attachment and create a file into SharePoint document library.

Step 2: In case of the invoice cannot be found into the subject, the flow will start searching the invoice keyword into the body of the email. If match found it’ll fetch the attachment and create the file into the SharePoint document library.

Let’s implement this solution.

Create Microsoft Flow

You have to follow these steps to create the invoice management with Outlook, Microsoft Flow and SharePoint integration.

Step 1: Go to the https://flow.microsoft.com/ and create flow from the blank.

Step 2: Set “When a new email arrives” trigger under the Office 365 outlook connector.

Step 3: Configure the details into the trigger of the flow.

You can select the specific folder in case you have specific folders into the Office 365 outlook by clicking on the highlighted icon into the above image.

Step 4: Trigger of our flow is now completed, now we have to check new mail’s subject for a specific keyword (In Our case its “Invoice”).

We have to create a condition into the Microsoft Flow. Click on the “New Step” button and then “New Condition”.

Step 5: To check the subject of the mail you should set condition “Subject of the Mail Contains” keyword or not.

Note: for example, I have used the “Invoice” as the keyword.


This condition checks for the Invoice keyword into the subject of the mail.

Step 6: If subject keyword found into the subject of the mail then we have to create the new file into the SharePoint document library named Invoice.

We must have the attachment to the mail, and then we can save it to the SharePoint document library so we need to check the attachment first.

Here as you’ll observe there is a for each loop will be created automatically it’s because mail can have more than one attachments.

We have to add the two actions into the first condition’s “IF YES” portion.

  1. First one is “Get Attachment” this action will fetch the attached document’s body.
  2. The second action is “Create a File” this action will create the file with the name of the attached document and also with the get attachment’s output the body of the attached document.

Configuration details of both the actions are given below.

  1. Get Attachment

    Message Id: Select Message Id under the “When a new Email Arrives” trigger’s output.
    Attachment Id: Select Attachment Id under the “When a new email Arrives” trigger’s output.
  2. Create file action in SharePoint

    Site Address: URL of the site where you have created the invoice library.
    Folder Path: Click on the folder icon and select the folder or document library for storing the document.
    File Name: Select attachments name under the “When a new Email Arrives” trigger’s output.
    File Content: Select the body from the “Get Attachment” actions output.

If the first condition fails we have to start the new condition to check into the mail’s body for invoice keyword.

For that, we have to perform below given steps

Step 1: Into the “If No” portion of the first condition, create one more condition by click on the more new condition.

Step 2: Here we need to search for specific keyword into the mail’s body weather, it contains the keyword or not.

Our condition will be like below

Step 3: On the “IF  YES” portion we’ll create the file same as the first condition’s “IF YES” portion and If it fails to find invoice keyword on both conditions than we’ll complete our flow and left blank the “IF NO” portion so our condition 2’s failure process will not be there, We’ll perform actions in the case of second condition’s success.

Step 4: Under the “If yes” portion of the second condition, click on “Add Action” button and select the “Get Attachment” action form Office 365 outlook connector.

Step 5: Add another action from SharePoint connector to create a new file.

Step 6: Here is the configuration for both the actions, yes, once you select any value regarding the attachment there will be automatic for each loop will be created, There is a reason, There are possibilities that someone can send the multiple attachments so for that reason the Microsoft flow automatically adds the for each loop.

Here are the configuration details of both the actions

  1. Get Attachment

    Message Id: Select Message Id under the “When a new Email Arrives” trigger’s output.
    Attachment Id: Select Attachment Id under the “When a new email Arrives” trigger’s output.
  2. Create file action in SharePoint

    Site Address: URL of the site where you have created the Invoice library.
    Folder Path: Click on the folder icon and select the folder or document library for storing the document.
    File Name: Select attachments name under the “When a new Email Arrives” trigger’s output.
    File Content: Select Body from the “Get Attachment” actions output.

Download the Package template from below Github URL:

https://github.com/mindlabco/Outlook–Search-For-Specific-Keyword-in-email-and-store-attachments-in-Document-library

Paras Dodhia

Leave a Reply