Written by

Vignesh

Share

  

Category

see all categories
intranet as a service

Create SharePoint flow for Outlook mail and save attachments into a SharePoint Library

Microsoft flow helps to automate lot of our day to day activity 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 attachment, then the below flow steps helps 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 flow for new emails which arrive to Inbox of the Outlook. 

Then choose "Inbox"from Folder to make flow for new mail which arrive to Inbox. 

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

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

webhook

Step 2: Get the email which have 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 email from the Inbox. 

Choose 'Message Id' for Message Id and make 'yes' for Include Attachments. 

message id

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 variable. The subject of the email assigned to the variable in this action.

subject value

Step 4:  Create an array with unwanted regular expressions  

Then, create an array and assigned full of regular expressions in the array. This action will help for the further process.  

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

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

Compose array

Step 5: Replace the regular expression while create folder with name of mail’s subject 

Replace the regular expressions as null because regular expressions which make issue while creating folder in 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(),'')

Dynamic content creation

Step 6: Push the attachments in the SharePoint library 

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

And give site address to store 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 limitation for name of the file.  

Then File Name is chosen as Name and File Content as content. This action make push the attachment in the file and named as their attachment name.

email attachments

Step 7:  Get the message of the mail 

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

Choose 'Message Id' for Message Id.

export email

Step 8:  Push the eml file in the SharePoint library 

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

Give site address to store 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 limitation for name of the file.  

Then File Name is chosen as Subject and then give .eml to create eml file.File Content as body to assign body of the email.This action helps to push the eml file to the folder. 

export email

I hope you learnt how to apply flow in your SharePoint flow for the Outlook mail. 

Vignesh

Written by Vignesh