Create SharePoint Flow For Outlook Mail And Save Attachments Into A SharePoint Library

Microsoft flows help to automate a lot of our day-to-day activities and keep things simple and easy.

In this article, we are going to discuss how to create a SharePoint flow for the Outlook mail.

If the mail has an attachment, then the below flow steps help you to save the attachments and store the .eml file of the mail.

Microsoft flow is designed in a way that anyone can use it without technical knowledge just by few clicks to apply conditions and steps. Let’s jump into the implementation.

Step 1 - Assign flow for arriving new emails in Inbox

Go to Microsoft flows and choose "Create from blank" option in your Flow.

Select the "Office 365 Outlook - When a new email arrives (webhook)" from the dropdown of Triggers to make a flow for new emails which arrive in the inbox of the Outlook.

Then choose "Inbox" from Folder to make flow for new mail which arrives at the inbox.

Click 'Show advanced setting' and changeHas Attachment' to yes to create a condition for the flow.

This condition helps to process only the emails with attachment. If the mail has an attachment and then moves for the next action, if the condition fails, the flow will not perform.

Create SharePoint Flow For Outlook Mail And Save Attachments Into A SharePoint Library 

Step 2 - Get the email which has attachments

Then Choose 'New step' and select the 'Add an action' option. 

Select 'Office 365 Outlook' icon from Connectors and choose 'Office 365 Outlook - Get email' option.

This action helps to get the email from the Inbox.

Choose 'Message-Id' for Message-Id and make 'yes' to include attachments.

Create SharePoint Flow For Outlook Mail And Save Attachments Into A SharePoint Library

 

Step 3 -Assign subject of the mail to a variable

Next, initialize a subject variable and then give a name and assign the type as 'string' and choose 'Subject' as value for the variable. The subject of the email is assigned to the variable in this action.

Create SharePoint Flow For Outlook Mail And Save Attachments Into A SharePoint Library

 

Step 4 -Create an array with unwanted regular expressions

Then, create an array and assign regular expressions in the array. This action will help for the further processes. 

Click “Add Dynamic content” and move to Expression then import the following code to create an array for the unwanted regular expressions in the “Expression” to remove from the subject and give a name for the folder as subject of the mail.

createArray(':','#','%','"','"','*','?','/','\','|','<','>','{','}','(',')','$','@')

Create SharePoint Flow For Outlook Mail And Save Attachments Into A SharePoint Library

 

Step 5 -Replace the regular expression while creating a folder with the name of mail’s subject

Replace the regular expressions as null because regular expressions make issues while creating a folder in a site. 

Then assign the output of the replaced value to the subject variable. To replace the regular expressions, click “Add Dynamic content” and move to expression, then import the following code in the “Expression” to perform the action.

replace(variables('Subject-Name'),item(),'')

Create SharePoint Flow For Outlook Mail And Save Attachments Into A SharePoint Library

 

Step 6 -Push the attachments in the SharePoint library

Next, choose SharePoint icon from the collector and select 'SharePoint – Create file' option from the action.

And give site address to store a file in the SharePoint library. In the folder path, give the folder name and give the file name as their subject to create for every file for their attachment. Use 'take' expression to set the limitation for the name of the file.

Then File Name is chosen as Name and File Content as content. This action pushes the attachment in the file.

Create SharePoint Flow For Outlook Mail And Save Attachments Into A SharePoint Library

 

Step 7 -Get the message of the mail

Choose 'Office 365 Outlook ' from the collector and 'export email' option from the action.

Choose 'Message Id' for Message-Id.

Create SharePoint Flow For Outlook Mail And Save Attachments Into A SharePoint Library

 

Step 8 -Push the .eml file in the SharePoint library

Then, choose SharePoint icon from the collector and select 'SharePoint – Create file' option from the action.

Give site address to store the file in the SharePoint library. In the folder path, give the folder name and give the file name as the subject to create every file for their attachment. Use 'take'expression to set limitations for the name of the file.

Then File Name is chosen as Subject and then give .eml to create an .eml file.This action helps to push the .eml file to the folder.

Create SharePoint Flow For Outlook Mail And Save Attachments Into A SharePoint Library

 

I hope now you know how to apply flow in your SharePoint flow or the Outlook mail.