GET IN TOUCH
+91-62843-00850
+1-732-668-8002
info@penthara.com
LOCATIONS
India
SCO 670, Third Floor
Sector 70, Mohali
Punjab, 160055
USA
651 North Broad Street
Suite 206
Middletown, DE 19709
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
Recommended Content
Email Insights
Get the latest updates from Penthara right in your mail box.
Sign Up
LinkedIn Newsletter
Monthly updates, news & events from Microsoft to help  your business grow.
Subscribe To Newsletter

Leave a Reply

Your email address will not be published.

More From This Category

Working with People Picker in Power Apps for SharePoint

Learn how to master People Picker columns in SharePoint from the Power Apps canvas app. In this blog post, you will find detailed step-by-step instructions on creating, updating, and clearing People Picker columns for single and multi-user setups in SharePoint.

Read More
Creating reminder Adaptive cards in Microsoft Teams for upcoming events from a SharePoint calendar list

Learn how to create an Adaptive Card in Power Automate that posts a summary of upcoming events like Birthdays, Work Anniversaries and Holidays to an MS Teams Channel. The source of these events is the SharePoint legacy calendar app. Advanced Dynamic JSON Adaptive Card implementation has been covered extensively in this example.

Read More
Exploring advanced customizations of react-table component within SPFx solution

Learn how to customize react-table within SPFx solution. In this blog post we have covered some advanced customizations and configuration options like conditional rendering of table data, adding hyperlink to table row, making a single cell clickable in a row, and maintaining pagination with react-table.

Read More
1 2 3