GET IN TOUCH
+1-732-668-8002
+91-62843-00850
info@penthara.com
LOCATIONS
USA
131 Continental Drive
Suite 305
Newark, DE 19713
United States
India
SCO 515, Third Floor
Sector 70, Mohali
Punjab, 160055
Follow Us on Social -
02.08.2021

Bringing back Incoming Email to SharePoint Online document library using Power Automate

This article will help achieve the erstwhile incoming email functionality using Power Automate, aka flows from specific domains. The flow can handle multiple attachments and special characters in the subject line. In addition, it includes failure notifications at multiple stages.

Objective

This article aims to outline the process for setting up incoming email functionality in SharePoint Online. This feature will help you receive incoming emails with attachments to the SharePoint document library.

Scenario

The Incoming email functionality allows the SharePoint sites to accept emails and store them in lists and libraries. This feature used the local SMTP server to provide this function. However, with Office 365, this feature has been deprecated.

This helps you store the mail contents sent to other recipients in SharePoint libraries without uploading the contents manually.

In this article, we help you achieve that functionality using a Shared Mailbox and a Power Automate flow, with a specific set of features:

  1. Save emails received from specific domains.
  2. Fix to clean special characters from the subject line for folder creation.

Prerequisites

  1. A SharePoint document library with an additional Text column for Mail Sender.
    • For this blog, we are using a document library with the name MailStore
  2. We need a Shared Mailbox, which will be used to receive emails that will be further uploaded to the SharePoint library.
    • For this blog, we are using a Shared Mailbox with the name IncomingMails
  3. Security requirements of Accounts – The accounts running the flow need to have access to the Shared Mailbox.

Configuration Steps

  1. We will be creating a flow with the action to trigger when a new item with an attachment is received in the shared mailbox.
  2. The flow further processes the mails to upload the mail content and attachments to the SharePoint document library.
  3. Browse to the Power Automate site using the account that has Power Automate License to create a new Flow
  4. Selected New Flow > Automated Cloud flow

     5. Specify the desired name (we have named it Save emails to Document Library) and under the triggers, select When a new email arrives in a shared mailbox (V2) (Office 365 Outlook). This will trigger the flow as soon as an item is created in our Shared Mailbox.

     6. In the trigger, specify the Shared Mailbox alias (IncomingMails) that we will be used to receive Incoming emails for the SharePoint document library.

  1. The Folder should be selected as Inbox
  2. In the advanced options, Only with Attachments & Include Attachments should be set to Yes
  3.  

     7. Initiate the following variables, which will be used further in the flow for calculations.

  1. From – This will be used to filter mails from specific domains and to update the Mail Sender field in the library
    1. Type: String
    2. Value: toUpper(triggerBody()?['From'])

     2. Subject – This will be used to create a folder in the document library to store the email and the attachments.

    1. Type: String
    2. Value: @{triggerBody()?['Subject']}

Steps to create the PowerApps.

     3. InvalidCharacters – This will be used to clean the Subject with any special characters to create a folder name

    1. Type: Array
    2. Value: createArray(':','<','>','?','/','|')

     4. Temp – This will be used to store the subject value temporarily until the special characters have been removed in the foreach loop

    1. Type: String
    2. Value: Blank

     8. In the next step, we remove the invalid characters from the mail subject, which will further be used to create a folder in the library.

The following expressions have been used in the above step.

  1. Loop for each invalid character
    • Expression: @{variables('InvalidCharacters')}

     2. Set Temp variable

    • Expression: replace(variables('Subject'),item(),'')

     3. Set subject variable after removal of invalid characters

    • Expression: @{variables('Temp')}

     9. In the next step, we add a condition to allow the processing of emails received from specific domains. This will ensure we filter out any unwanted emails.

     10. In the next step, we filter out emails that do not have attachments.

Expression: @triggerBody()?['HasAttachment']

     11. In the next step, we further process the emails that have attachments.

     12. We first export the contents of the email using the Export email (v2) action. This will be used to upload the email contents to the document library.

Expression: @{triggerBody()?['Id']}

     13. The next step is to create a folder in the document library using the subject as the name.

Expression: @{variables('Subject')}

create folder subject flow

     13. Change the text from "Button" to "Create Single Person."

Changing-Text-Property-of-button

     14. The next step is to send an email to the admin in case of the previous step of folder creation failure. This will have a run after configuration as below. The content of the email can be customized as per requirements.

folder creation failure notification flow

Go to the Send an email notification settings – New Folder Failed step and then click on Configure run after. Uncheck all options and select has failed. This will ensure that the email will be triggered only when the create folder action fails.

     15. The next step is to create the eml file in the Subject named folder created earlier.

Expressions:

  • Folder Path: /MailStore/@{variables('Subject')}
  • File Name: @{concat(triggerBody()?['Subject'],'.eml')}
  • File Content: @{body('Export_email_Content')}

This will also have a run after configuration to run only when the previous step is skipped. This will ensure that if the new folder creation fails and the email notification is triggered, then create eml file will not be triggered since the folder creation had failed earlier.

     16. The next step is again to send an email to the admin in case of the previous eml file creation failure. The contents of the email can be customized as per requirements.

This will run after configuration as below to ensure that the email will be triggered only when the create eml file action fails.

     17. The next step is to update the properties of the eml file created in the previous step.

Expressions:

  • Id: @{body('Create_eml_file')?['ItemId']}
  • MailSender: @{variables('From')}
update file properties action

This step will run after configuration as below to ensure it will be triggered only when the previous step is skipped. This will ensure that if the new eml file creation fails and the email notification is triggered, then create update file properties of eml file will not be triggered since the eml file creation had failed earlier.

     18. In the next step, we check-in and publish a major version of the eml file created in the earlier steps. This will make it visible to authorized users.

Expressions:

  • Id: @{body('Create_eml_file')?['ItemId']}

     19. The next step is to use the Apply to each action. This will loop through each attachment in the email and save it in the same Subject named folder created earlier.

Expression: @{triggerBody()?['Attachments']}

     20. The next step is to create a file from the attachment in the Subject named folder created earlier.

Expressions:

  • Folder Path: /MailStore/@{variables('Subject')}
  • File Name: @{items('Apply_to_each')?['Name']}
  • File Content: @{items('Apply_to_each')?['ContentBytes']}

     21. The next is to send an email to the admin in case of the previous step of attachment file creation failure. This will have a run after configuration as below. The contents of the email can be customized as per requirements.

Go to the settings on the Send an email notification – file attachment Failed step and then click on Configure run after. Uncheck all options and select has failed. This will ensure that the email will be triggered only when the create attachment file action fails.

     22. The next step is to update the properties of the attachment file created in the previous step.

Expressions:

  • Id: @{body('Create_file_from_attachment')?['ItemId']}
  • MailSender: @{variables('From')}
update file properties action

This step will run after configuration as below to ensure it will be triggered only when the previous step is skipped. This will ensure that if the new attachment file creation fails and the email notification is triggered, then create update file properties of the attachment file will not be triggered since the attachment file creation had failed earlier.

 

     23. In the next step, we check-in and publish a major version of the attachment file created in the earlier steps. This will make it visible to authorized users.

Expressions:

  • Id: @{body('Create_file_from_attachment')?['ItemId']}

Summary

The above steps helped us achieve the Incoming email functionality that allows the SharePoint sites to accept emails and store them in lists and libraries.

The Power Automate flow has the following features.

  1. Save emails received from specific domains.
  2. Fix to clean special characters from the subject line for folder creation
  3. Handle failures and notify admins at file creation and upload stages.
  4. Upload multiple attachments
Written By
Aneesh Kumar
Aneesh Kumar
M365 Solution Architect
peer reviewed By
JAsjit Chopra
chief executive officer
Graphics designed By
sanika sanaye
Creative Design Director

Leave a Reply

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

More From This Category

Asset & Inventory Management (AIM) App: Deployment Guide

This deployment guide is designed to help admins effectively deploy the Asset & Inventory Management (AIM) app to their environment. It provides step-by-step instructions and information about deploying the app in the environment.

Read More
Starfleet Stash App: Deployment Guide

This deployment guide is designed to help admins effectively deploy the Starfleet Stash app to their environment. It provides step-by-step instructions and information about deploying the app in the environment.

Read More
Top 5 Reasons to use Microsoft Power Platform for your Business.

In today's fast-paced and ever-changing business landscape, companies are constantly looking for ways to optimize their processes, reduce costs, and increase efficiency. The Microsoft Power Platform offers a range of solutions that can help businesses achieve these goals.

Read More
1 2 3 4
chevron-right