Recently while working on a SharePoint On-Prem to SharePoint Online migration, we came across a scenario where the customer used incoming emails heavily for the specific site collection, and they wanted to continue using it in SharePoint Online after the migration.
That made me look into different alternatives available to implement incoming emails in SharePoint Online, I came across following options with quick google search:
Azure Logic Apps
Create a new app in Azure Logic Apps, which is similar to flow, track emails of a mailbox and configure the app as per the business logic. The customer did not have an Azure Logic Apps license, so we didn’t want to go with this option at that point in time.
- Shared Mailbox: Users can use a Shared Mailbox to monitor emails, but the users wanted to more with emails, like routing specific emails to specific folders and extract the attachments and store them in SharePoint.
- Microsoft Teams: Each channel in teams has an email address. Users can send emails to channel email address and those emails will get store in Teams’ SharePoint Document Library. We did not go ahead with this option because users did not want to use the Team’s site collection as there was a specific site collection created and configured for the users for this business case.
- Microsoft Flow aka Power Automate: Flowability to track emails of a mailbox and do further processing on emails and store those emails and its attachment in SharePoint. So this is what we wanted to do, and customers also had a Flow license as part of their O365, so we decided to go ahead developing a Flow for this customer scenario.
Below are the details of the Flow we developed to implement incoming emails in SharePoint
Flow has connectors which help us to connect to other services, here we wanted to connect to Office 365 outlook and SharePoint. There are two types of Connectors in Flow one is Trigger and another is Action.
We used the “When a new email arrives” trigger for a Shared Mailbox and provided the credentials of Shared Mailbox in the connection. We tried to use the trigger “When a new email arrives in Shared Mailbox”, but that didn’t work as it was throwing an error and not triggering when new mail arrived in Shared Mailbox. That could be because the specific Shared Mailbox that we used was initially user mailbox and then it was converted to Shared Mailbox. We had to contact MS support to further troubleshoot that error, but we were short of time, so we did reset the password for Shared Mailbox and used the username and password for the connection of the trigger.
Actions are the way to implement business logic in the Flow. Using Actions, we can perform, CRUD operations or communicate to other applications or perform data manipulation.
Export Email – Action
Provide the Message-Id from the “When a new email arrives” dynamic content
Strip out special characters from Subject
As we will be using Subject as the file name of the email file, we will strip out the special characters from the subject, follow below steps to do that:
Initialize Subject Variable
Using “Compose” action, create an array of special characters
Use below Expression:
Using Apply to Each
In an Apply to Each loop, replace special characters from Subject. Use the output from the previous step, i.e. the previous compose Action output
Compose – Replace Special Characters
Use the expression:
Set Variable – Save the output of replacing special characters to variable
Save email as File to SharePoint
Use Create File (SharePoint) action to save the email as .eml file to SharePoint Library
Provide the following values in Create File Action attributes:
Site Address: Here you may want to change the connection account if you don’t want your name to appear in the Created By and Modified By column values when a file is created in SharePoint
Folder Path: Provide Web Relative URL of the folder in a library or to the root of Library
File Name: Use Subject-Name variable as defined in steps before
File Content: Use the Body from Dynamic Content of Export Email action