How to upload files to sharepoint by sending an email

SharePoint Online is a web-based collaboration and content management platform developed by Microsoft. It serves as a central hub for organizations to create, manage, and share information, documents, and resources among their teams and employees.

Uploading a file to sharepoint document library via email is possible using Incoming email support for the Document Library Settings, Picture Library Settings, or Form Library Settings. But this feature is available only for On-prem Sharepoint sites and not for Sharepoint Online sites.

There are few alternative solutions of this. One of the alternatives which we will use is Power Automate flow. Power Automate is a cloud-based service provided by Microsoft that allows users to create automated cloud workflows for various apps and services.

Scenario

Third party vendor has requested you to create a dedicated sharepoint site to upload and share documents with your company users. This involves configuration of External Access settings on sharepoint admin center and configuration of Azure B2B collaboration configuration.

After you have configured External Access in sharepoint and Azure B2B, you can then invite a guest user to your Azure AD tenant and provide access to the sharepoint site where external vendor can upload and download the files.

However, some Organizations security policies does not allow External Access to Sharepoint and also have Azure B2B collaboration disabled. This is the most secure settings that could protect the organizations from external threats. However, its the least flexible also and may not be best for collaboration with the External partners.

To upload files to sharepoint online document library without changing any of the External Access settings or Azure B2B collaboration setting is to use Power Automate flow. Before we proceed to create a Power automate flow, please make sure you have the right type of Power automate license assigned to you to create and work on Power automate.

I will start from scratch by creating a sharepoint site and then a document library. Files which are sent as attachment to a specific email address will be automatically uploaded to this sharepoint document library.

Create a Sharepoint Site

If you already have a Sharepoint site and a document library in which you want to upload the files via email, then you can skip this step. Let’s check the steps to create a sharepoint site.

  • Login on Microsoft 365 admin center > Click on Sharepoint under Admin centers.
  • Go to Sites > Active Sites.
  • Click on + Create link.
  • Select Team Site option on Create a Site pane.
  • Provide a Site name, Group Owner information.
  • Click on Next and then Click on Finish to create a site.
Create a Sharepoint Site
Create a Sharepoint Site

Create a Document library

Document libraries can be used to store a variety of files, including documents, spreadsheets, presentations, images, and videos. You can also create folders within document libraries to further organize your files.

For creating a document library in sharepoint site. Please follow below steps:

  • Login on Microsoft 365 admin center > Click on Sharepoint under Admin centers.
  • Go to Sites > Active Sites.
  • Find your site under Site Name Column and click on URL under URL column to launch the site.
  • Click on New > Document Library while on Site’s Home page.
Create a Document library
Create a Document library
  • Provide a Name of the library. Keep the checkbox ticked for “Show in site navigation” and then click on Create button to create a Document library in this sharepoint site.
Provide a name of the sharepoint document library
Provide a name of the sharepoint document library

Create Power Automate Flow

Now we have a Sharepoint site and a document library created. We can create a Power Automate flow to automate the file upload to this document library via email. Please follow below steps to create a flow:

  • Go to the Sharepoint site called EmailUpload and then Click on the ExternalFilesStore Document library created in the previous step.
  • From the Menu bar at the top of the document library, Click on Integrate > Power Automate > See your flows
Create Power Automate Flow from Sharepoint document library
Create Power Automate Flow from Sharepoint document library

This will automatically launch https://make.powerautomate.com/flows site where you can create a New Flow. Please follow below steps to create a New Power Automate Flow.

  • Click on + New flow drop down and then select Automated cloud flow option under Build your own from blank category.
Click on New flow > Automated cloud flow
Click on New flow > Automated cloud flow
  • There will be a pop up for Building an automated cloud flow. Provide a relevant Flow name and choose your flow’s trigger as “When a new email arrives (V3)”.
  • Flow Name: CloudInfraSPO-FileUpload-viaEmail
  • Flow’s trigger: When a new email arrives (V3)
Select flow trigger as When a new email arrives (V3).
Select flow trigger as When a new email arrives (V3).
  • A flow will be generated and a trigger form with list of options is presented in front of you. You will need to provide the information in the form as per your requirement.
  • Folder: Inbox will be selected by default but you can click the folder Icon and select any other folder as well. The cloud flow will trigger only when an emails arrive in that specific folder. I will keep it as default for now which is Inbox.
  • To: Automated cloud flow will trigger when emails are sent to this email address.
  • CC: Automated cloud flow will trigger based on CC email address.
  • To or CC: Automated cloud flow will trigger if the email address specified is either in To or CC field.
  • From: Automated cloud flow will trigger based on sender’s email address.
  • Include Attachments: Select as Yes to include attachment content bytes instead of null as we are going to use Sharepoint Create file action later to pull the content of the attachment. Keeping it at No will result in 400 Bad request error.
  • Subject Filter – Automated cloud flow will trigger if the words provided in this field matches with the any of the words in the email subject.
  • Importance – Automated cloud flow will trigger based on the importance of the Email. For example: Low, Normal or High Priority emails.
  • Only with Attachments – If its set to Yes, Automated cloud flow will trigger only if the email contains an attachment

Click on + Next Step to proceed to add a new step in the flow.

When a new email arrives (V3) Power automate form
When a new email arrives (V3) Power automate form

Now we have created the trigger for an email. I have Provided below values on “When a new email arrives (V3)” trigger form.

  • Folder: Inbox
  • To: Jatin.makhija@cloudinfra.net
  • From:Jatin.makhija@gmail.com
  • Include Attachments: Yes
  • Importance: Any
  • Only with Attachments: Yes

After the Automated cloud trigger starts, and an email is received with an attachment, What action we want to take on it ? We have to define that operation now. Let’s choose an operation and search for Sharepoint from provided search box. Once you find Sharepoint Icon, Click on it.

Add Sharepoint step in Power automate flow
Add Sharepoint step in Power automate flow

Find Create file Action from the list of available Sharepoint actions.

Select Create File for Sharepoint Power Automate flow action
Select Create File for Sharepoint Power Automate flow action

Click on the drop-down in Site Address field to select the Sharepoint site where the documents will be uploaded. If you do not see the site in the list, Please make sure you have permissions to access the site. Alternatively, you can click on Enter custom value and provide Site address manually.

Select the sharepoint site from Site Address drop down
Select the sharepoint site from Site Address drop down

Click on Folder Icon in Folder Path text field to select the Document Library where the files will be uploaded. As we had created ExternalFilesStore document library, we will select this folder.

Provide document library name in the Folder Path field by clicking on folder Icon

Click on the File Name field and then search for Attachments Name under Dynamic content tab. Click on Attachments Name to select and provide the value to File Name field.

Select File Name as Attachments Name. This will be the name of the files which will be uploaded to SPO
Select File Name as Attachments Name. This will be the name of the files which will be uploaded to SPO

Click on File Content field to select Attachment Content under Dynamic content tab. Click on Attachment Content to provide the value to File Content field.

Provide File Content as Attachments Content
Provide File Content as Attachments Content

Here’s is the Final Power Automate Flow with all the values. In the next steps we will test this flow to see when it triggers and if it creates / uploads email attachments to Sharepoint site document library ExternalFilesStore. Please do not forget to click on Save button to save the flow.

Power automate flow for uploading documents to sharepoint library via Email
Power automate flow for uploading documents to sharepoint library via Email

Testing Power Automate Flow

Now we will test this Power Automate Flow. Please follow below steps to test the flow:

  • When you have already opened the flow in Edit mode. You can click on Test button on the top right hand side corner and then select Manually and then click on Test.
Testing Power Automate Flow
Testing Power Automate Flow
  • After you click on Test button, The flow will start, You can now start the trigger by sending an email to the email address provided in “When a new email arrives (V3)” form. In my case, its jatin.makhija@cloudinfra.net. Therefore, I will be sending an email to this email address with Attachment.
  • Please make sure the email is sent from a Sender address which is provided in From field of the Power automate flow. In my case, its jatin.makhija@gmail.com. Let’s test.
Send an email to Power automate Email trigger email address
Send an email to Power automate Email trigger email address
  • When recipient receives this email in the Inbox folder with attachment. The power automate cloud flow we created will be triggered. You will be able to confirm it in real time when the test completes, it will provide the results of the flow testing on the screen.
  • You can see the message that “Your flow ran successfully” and Green tick next to each flow operation.
Power automate Flow ran successfully. You can see the two green tick to confirm this.
Power automate Flow ran successfully. You can see the two green tick to confirm this.
  • Let’s check if the file which we sent as an email attachment has been uploaded to the Sharepoint document library ExternalFilesStore. As you can see in below screenshot, testdoc.docx file has been uploaded successfully into the ExternalFilesStore.
Confirmation of the File which is successfully uploaded to sharepoint online document library ExternalFilesStore
Confirmation of the File which is successfully uploaded to sharepoint online document library ExternalFilesStore

Conclusion

In this blog post, we have learned how to upload documents in a particular sharepoint library by sending an email with attachment. There are a lot of steps to go through however all makes up for it in the end when it works successfully. It also saves a lot of time having to manually upload a file to sharepoint library when an external vendor may share it over an email. You can tweak the solution as per your requirement like you can add an additional step to send a notification on slack or having someone approve the file upload process via Slack or Teams.

READ NEXT