Sometimes it makes a lot of sense to send a document as an email attachment and have it saved to a SharePoint document library. A common scenario is emailing a scanned document from a network copier to a SharePoint document library. For those using SharePoint on-premises there is the incoming email service that can establish an email-enabled list. If your organization is using Office 365 and SharePoint Online it is not so easy. Office 365 and SharePoint Online do not have the ability to create a list or library that has an email address.
Microsoft has recently developed a new product called Microsoft Flow. Flow is a cloud-based workflow engine that can connect to a variety of common cloud services to provide notifications, manipulate data, and automate processes. In this post, I will demonstrate using an Exchange Online mailbox to receive emails and then use Microsoft Flow to extract email attachments and drop them in a SharePoint document library. This will provide the ability to “email a document” to a SharePoint Online document library in Office 365.
Create a New User in Office 365
We need to establish a new mailbox in Exchange Online to receive the emails. A shared mailbox will not work because there is not a user associated with it to login. Flow will need to login to both Exchange and SharePoint as a user that has a license for both products. There is not a Flow activity (yet) to connect to a shared mailbox requiring us to use the logged in user’s mailbox. As a best practice, it is not a good idea to mix an actual user’s mailbox with one we will use for automated document routing. Therefore, we will need to create a new licensed user in Office 365. However, we do not need to establish a new user for each document library that we want to send emails to. We will create a single mailbox with multiple email addresses that will handle routing to multiple document libraries. In this article, I will demonstrate using a single account for multiple document routes to SharePoint Online.
We will first create a new user with a generic email address (not the address we will use to route documents).
When assigning licenses, you only need to activate Exchange Online and SharePoint Online.
Create an Alias For Each Document Route
We may have multiple destination document libraries, each with a dedicated email address. For example, when an email is sent to [email protected] we would like those documents to be placed in the Expense Reports library in the Finance department team site. When an email is sent to [email protected] those documents should be placed in the Documents library in the Marketing team site.
We will use a single, underlying mailbox to receive all emails that will be routed to SharePoint, regardless of the destination. To do this, we will give the mailbox an email alias for each route.
We can now send emails to this mailbox using an email address of [email protected]
Email Folders and Inbox Rules
We will need to sort the email into folders so that Flow will be able to route the emails to SharePoint appropriately (later in this article). For each route, we will create a folder and an Inbox rule to move emails into the correct folder as they arrive. You will need to log into Outlook Web Access as the new user you created earlier. Once you are logged in you can create a folder for the route and the matching Inbox rule to move messages into the correct folder.
When creating the Inbox rule we will match messages based upon values in the message header instead of the To address. Exchange Online modifies the To field of messages to match the name of the user account, which removes the original address from the To field. The message header will retain the original To address so we will use that when creating our rule.
Once you have specified the settings for the rule, click OK. Now, whenever a message is sent to [email protected] it will be placed into the Expense Reports folder.
Grant Permissions In The Destination SharePoint Library
To save a document in the desired SharePoint document library the SharePoint Distribution account must be granted access. Browse to the document library where the attachments will be saved. Use the Share feature and grant contribute access to the SharePoint Distribution user account.
Create a Microsoft Flow to Move Email Attachments To SharePoint
To create a Microsoft Flow browse to https://flow.microsoft.com and login with the SharePoint Distribution account that you created earlier. We will use an existing Flow template that will extract attachments from new emails that have been moved to the new folder that was created. The Flow will then save the attachment to the destination SharePoint document library.
To create the flow, start by using the search templates… box at the top of the screen and search for “email sharepoint”.
In the template results, select the template called Save my email attachments to a SharePoint document library.
Next, you will need to click Use this template and log in to both the Office 365 Outlook and SharePoint Online connectors. After clicking each of the Sign in buttons a dialog will briefly open, just wait and it will close once Flow has completed the sign in.
Start with the action for On new email. Enter the name of the mailbox folder that you created earlier.
Next, select the SharePoint site and library where attachments will be saved.
At this point, the Flow is configured to save attachments to the Expense Reports document library when new messages arrive in the Expense Reports mailbox folder. Once the attachments are saved, we can optionally remove the original message from the mailbox. We will add a new Office 365 Outlook – Delete email step to clean up the message. At the bottom of the Flow, click New step. Then, Add an action and search for Delete email.
Configure the action to use the Message Id output of the On new email action to delete the message.
The completed Flow should look like this. Now, give your Flow a name and click Create Flow.
Start Sending Messages
You are now ready to start sending messages. All you need to do is to configure your multi-function copier, reporting application, or whatever else that you want to send emails with attachments from and they will end up in your SharePoint document library.
Set Up Additional Routes
You can set up routes to other document libraries. You will use the same mailbox and Flow account. To add additional routes you will need to:
- Add an alias to the SharePoint Distribution user mailbox.
- Create a new folder and Inbox rule to sort messages using the email address in the message header.
- Grant permissions to your destination document library.
- Create a new flow.