Power Automate save email attachment to SharePoint

In this Microsoft flow or Power automate tutorial we will discuss how to save my email attachments to a SharePoint document library Power Automate or flow. Let us see, a few examples of Power Automate save email attachment to SharePoint.

  • Power Automate save email attachment to SharePoint library
  • Power Automate save email attachment to SharePoint with different name
  • Power Automate save email attachment to SharePoint list item
  • Power Automate save multiple email attachment to SharePoint
  • Power Automate save excel email attachment to SharePoint

Basically, it will save the attachments coming to my Office 365 email box.  We will also see how to save email attachments from a particular person or from a particular email address to the SharePoint library through a flow.

If you are new to Microsoft flow of power automate I can check out an article that I wrote on what is Microsoft flow and how to start with Microsoft flow.

Power Automate save email attachment to SharePoint library

When we send an email with the attachment it takes a lot of internal space. To avoid this, we can store the attachment in a specified document library or folder of the SharePoint site and archive the mails. In this way, we can save internal space.

So for this, here we will create a Microsoft flow that will trigger when a new email will arrive with an attachment.

For this go to https://flow.microsoft.com and then click on + Create -> Instant cloud flow.

power automate save email attachment to SharePoint
power automate save email attachment to SharePoint

Then we will add another action under this trigger i.e. Apply to each. Here it will ask to select an output from previous steps. So we will add Attachment as output.

power automate save email attachment to SharePoint document library
power automate save email attachment to SharePoint document library

Again we will add an action inside the apply to each i.e. Create file(SharePoint).

 Save email attachments to a SharePoint document library
Save email attachments to a SharePoint document library

Now our flow is ready to run. Let’s test it.

Testing

For testing, here we will send an email with an attachment from a testing user ID.

MS Flow To Save Email Attachments To SharePoint Library
MS Flow To Save Email Attachments To SharePoint Library

When we will click on the attachment it will store on the specified folder path.

 Save email attachments to a SharePoint document library Power Automate
Save email attachments to a SharePoint document library Power Automate

This is how to save an important email attachment to the SharePoint document library.

Read Power Automate email body formatting

Power Automate save multiple email attachments to SharePoint

Similarly, we will see how to save multiple email attachments to SharePoint. Now we will use this flow to see this requirement. For example, here we will attach multiple attachments such as images, PDFs, Word files, etc. in an email and that will send us from another user.

The flow will be exact the above one.

Microsoft flow save multiple email attachments to SharePoint list
Microsoft flow save multiple email attachments to the SharePoint list

Since the flow already has the Apply to each block, so it will read all the attachments and save the attachments to the document library.

Once the flow triggers, you can see the multiple attachments are stored at a time in the SharePoint document library:

Power Automate save multiple email attachments to SharePoint
Power Automate save multiple email attachments to SharePoint

This is how to do save multiple email attachments to SharePoint using Power Automate.

Read How to use Rest API in Power Automate

Power Automate save excel email attachment to SharePoint

Now, let us see, how to save excel email attachments to a SharePoint library using Power Automate.

If the email has multiple attachments like (.xlsx, .pdf, .txt, .png, etc), it will only save the excel files (.xlsx or .xls).

For this, I have again created an automated flow (Go to https://flow.microsoft.com, then click on + Create -> then choose Instant cloud flow).

Here in the Appy to each block, first I have added one condition, that will check if the Attachment name contains .xlsx or .xls. These I have put in an Or condition.

If it is Yes, I am creating the file using the Create file flow action and if it is No, then we are not doing anything. You can check out the screenshot below:

save only Excel email attachments in SharePoint document library
save only Excel email attachments in the SharePoint document library

Let’s test the flow by sending some attachments like excel files and word files from a test user to ourselves.

power automate save excel email attachment to SharePoint
power automate save excel email attachment to SharePoint

Once our flow run, we can see only the excel files are saved in the SharePoint document library (in the specified folder path).

save excel email attachment to SharePoint power automate
save excel email attachment to SharePoint power automate

This is how to save excel attachments to SharePoint using Microsoft flow. You can download this flow from here also.

Power Automate save email attachment to SharePoint with different name

Here, we will see how to save email attachments to SharePoint with a different name or how to rename the email attachment. For this, the following steps are:

Step-1:

On Power Automate, let’s trigger the flow by adding the trigger When a new email arrives(V3). Here we have to choose a folder where a new email arrives. So we will select ‘Inbox‘.

power automate save email attachment to SharePoint with different name
power automate save email attachment to SharePoint with a different name

Step-2:

Now we will add an action to initialize a string variable that will use to rename the email attachment process.

Manipulate filename from email attachment - Power Automate
Manipulate filename from email attachment – Power Automate

Step-3:

In the next step, we will add an action as Apply to each loop. That will help to rename each attachment and save it to SharePoint.

In that loop, we will select output Attachments from previous steps. Inside that loop, we will add another action i.e. Set variable. Here, we will use the first variable that we have initialized i.e. VarName, and set the value as Attachments Name.

Rename Email Attachment using Flow
Rename Email Attachment using Flow

Step-4:

Inside that loop, next, we will add a compose to extract the attachment or filename using the below expression:

first(split(variables('VarName'),'.'))

Step-5:

Similarly, we will add another Compose to extract the extension of the attachments or files name using the below expression:

last(split(variables('VarName'),'.'))
Rename Email Attachments using Microsoft Flow
Rename Email Attachments using Microsoft Flow

Step-6:

Again, we will add another Compose action using an expression that will concatenate both the first name and extension of the attachment with a date i.e. on which date the attachment was received. For example, if we got an email attachment i.e. XYZ.png then it will be saved as XYZ-29112021.png.

For this, the expression is:

concat(outputs('Compose_for_attachment_name'),'-',formatDateTime(utcNow(),'ddMMyyyy'),'.',outputs('Compose_for_attachment_extension'))
Using Power Automate to Automatically Move Your Email Attachments to SharePoint and rename it
Using Power Automate to Automatically Move and rename Your Email Attachments to SharePoint

Step-7:

In the final step, we will add an action Create file under SharePoint that will create the modified file inside the specified SharePoint folder:

Renaming a File in SharePoint Online using Flow
Renaming a File in SharePoint Online using Flow

Now our flow is ready to run and test. Let’s test the flow by sending an attachment in an email to yourself:

save email attachment to sharepoint with different name Ms flow
save email attachment to SharePoint with different name Ms flow

It will save in different names having today’s date in SharePoint:

save email attachment to sharepoint with different name in Power Automate
save email attachment to SharePoint with a different name in Power Automate

This is how to save email attachments to Sharepoint with a different name in Power Automate. For reference, here we have attached the whole flow. You can download this from here.

Power automate save email attachment to sharepoint list item

Here, we will see how to create a new item automatically and save email attachments to the SharePoint list.

For this requirement, there is a default template named ‘Create item and add attachments to a SharePoint list on a new email arrival‘ that is available on Power Automate.

power automate save email attachment to sharepoint list item
power automate save email attachment to SharePoint list item

Select the template and then click on Continue to create an automated flow:

Create item and save email attachment to sharepoint list on power automate
Create item and save email attachment to SharePoint list on power automate

To save the email attachments, we have created a SharePoint list like below:

Where, Title: a single line column

About: a multiline column

MS flow to create item and save email attachment to sharepoint list
MS flow to create a new item and save email attachments to SharePoint list

Let’s see how the flow works on flow and on SharePoint list:

Step-1:

First, we have to choose a folder to where the new email arrives. Then we have to insert the site address and SharePoint list name.

power automate create item and save email attachment to SharePoint document library
power automate create an item and save email attachment to SharePoint document library

Step-2:

Similarly, in the Add attachment action, insert the Site address and List name:

MS flow save email attachment to sharepoint list item
MS flow save email attachment to SharePoint list item

Now our flow is ready to run. Let’s test it by sending an email with an attachment to yourself:

power automate save email attachment to sharepoint list creating new item
power automate save email attachment to SharePoint list creating a new item

Now we can see, a new item is created and saved this attachment in the SharePoint list:

Microsoft flow save email attachment to sharepoint list item
Microsoft flow save email attachment to SharePoint list item

Send my email attachment to a SharePoint document library (using Template)

A lot of times you might require to save important email attachments to the SharePoint document library. Or maybe you want to save the attachments coming from a particular person like your manager or CEO or director.

So in this example, we are going to use the Microsoft flow templatesave my email attachments to a SharePoint document library” to create a flow,  that will save all the email attachments from everyone to the SharePoint library.

As well as I will show you how to specify a particular from address, and emails coming from that particular email address if contains attachments, then it will save to the SharePoint library.

 Let us see how to create this flow.

Login to https://flow.microsoft.com and then provide your office 365 credentials to log in.

Once login in from the left navigation click on the Templates button And then search for the template “Save my email attachments to a SharePoint document library” like below.

Then Select the template.

Save my email attachments to a SharePoint document library
Save my email attachments to a SharePoint document library

Then make sure to connect to SharePoint, Office 365 outlook and Office 365 Users.

Save my email attachments to a SharePoint document library flow

Then click on Continue. Once you click on the Continue button it will create the flow and the flow looks like below:

save email attachments to sharepoint

Now let us understand how this flow works.

First, we need to select the folder, for this click on, on new email with attachment flow action. Their select Inbox, you can also select other folders of your email like Archive, Conversion History, Deleted Items, Draft, Junk Email, etc like below:

save email attachments to sharepoint document library

Then you can see Microsoft flow added a few other flow actions like Initialize variable and Condition. The first time the value of the IsFromFilterApplied variable is False, that means there is no from address filter is there.

So it will save all the attachments coming from any email address.

Later, we will make it to true and we will see how it is working for a particular From address.

Since the variable condition is set to No, it will go to the No condition. And this will save attachments to the SharePoint document library.

how to save email attachments to sharepoint library

Here, select your SharePoint Online site and the SharePoint document library where you want to save the email attachments.

save my email attachments to a sharepoint document library

Note: Make sure to provide the site address and SharePoint document library name in both Yes and No condition.

And if for any reason, it is not able to create the file or save the attachment to the SharePoint library, then it will trigger an email to the user. In those case the status error code will be 403.

microsoft flow save my email attachments to a sharepoint document library

Now, we can test the flow. So save the flow and then when you receive an email with attachment(s) from others you can see the attachment(s) got saved to the SharePoint library.

save my email attachments to a sharepoint document library flow

Once you received an email, the flow will trigger and you can see the file will be created in the SharePoint document library.

save my email attachments to a sharepoint document library power automate

Save my email attachments to a SharePoint document library automatically from a particular email address

Now, we will see how to save my email attachments to a SharePoint document library automatically from a particular email address.

We need to edit the flow and for this, we need to change in two places in the flow.

1st modification:

First, we need to set IsFromFilterApplied variable value to true.

Edit the flow and click on Initialize variable workflow action, go to Expression, type true, and click on OK.

microsoft flow save my email attachments to a sharepoint document library

Now, the value of the variable will be true like below:

save my email attachments to a sharepoint document library automatically

2nd Modification:

Now, we need to set the From email address in the Check From email address flow action. That will available in the If Yes part.

There provide the email address. In this case, you can see below I have provided the email address.

save my email attachments to a sharepoint document library flow

Microsoft Flow email address case sensitive

I want to add a note here, the Microsoft flow email address is case sensitive. So the From email address you are providing here will be case sensitive.

So if you are not sure, what exactly your from Email address is, you can add a variable and try to send the From email address value like below:

Microsoft flow email address case sensitive.

Here, I have just created a string variable and assign the From value to it and then I am sending the value in my email. This is just a way to get the exact email id.

microsoft flow email address case sensitive

Now, our flow is ready for testing. Now, if an email is coming from the particular email address, then the attachment will be saved to the document library.

If the email is coming from other email addresses then it will not save.

Here I have sent an email from Bhawana email address like below:

save my email attachments to a sharepoint document library

The flow triggers and you can see the attachment got saved in the SharePoint Online document library.

save my email attachments to a sharepoint document library flow

This is how we can save my email attachments to a SharePoint document library automatically.

What will happen if the attachment already exists in the SharePoint document library?

Lot of time you will see the attachment or file with the same name already exists in the SharePoint document library, what the flow will do that time?

It will override the file, basically it will replace the new file with the old file.

If email contains multiple attachments?

If the email contains multiple email attachments, then it will save all the files in the SharePoint document library.

In this tutorial, we learned how to save my email attachments to a sharepoint document library using Power Automate or Microsoft flow.

Also, we explore how to configure the flow, so that it will save my email attachments to a SharePoint document library only if it is coming from a particular email address.

In this tutorial, we learned Power Automate save email attachments to SharePoint with a few examples.

  • How to save email attachment to sharepoint document library on Power Automate?
  • How to save multiple email attachments to sharepoint document library on Power Automate?
  • How to save excel email attachment to sharepoint document library on Power Automate?
  • How to save email attachment to sharepoint with different name on Microsoft flow?
  • How to create new item and save email attachment to sharepoint list on Microsoft Flow?

You may like the following Power Automate tutorials:

  • Hi sir
    Is there a way to upload pdf documents from local to multiple share point lists based on ID

  • Thank you Bijay! I have a question – we have an email called accounting to which all our vendors send thier invoices to. I need all attachments that are sent to that email to be saved to Sharepoint. So instead of from email address do I use to email address?

  • I cannot wrap my head around this particular flow. Why does it need IsFromFilterApplied condition? Cannot I just specify “from” e-mail address in trigger if I want this flow to save attachments from mails from particular person? What’s the difference?

  • Hi Bijay,
    Thank you for these lessons..really appreciated it.
    I have tried one of the flows to save and rename the file in the share point whenever a new email attachment comes to the inbox. But unfortunately, I am getting the error, It’s creating duplicate files, actual files and files with date …. How to resolve this?

  • Hi Bijay.
    Great tutorial. I am new to powerflow. I want to get mail attachment(s) of type excel table and extract data to share point list. Is it even possible achieve in one or two flows.
    Best regards.

  • Hello,

    Can you confirm me is there a way to upload images directly from FTP server to a sharepoint online library/folder.

  • >