Power Automate – Export email attachments to Onedrive

Introduction

In this post let us learn how we can export email attachment(s) to Onedrive using Power Automate. In my previous post Power Automate – Export email to Onedrive | Knowledge Share (spknowledge.com) we learned how to export email to Onedrive but the downside is the attachments are not exported and the .eml file in Onedrive shows the attachment name and not the actual file. Now we are gonna export the attachments into a separate folder.

Let’s start building Power Automate Flow

When a new email arrives (V3) – Auto Trigger

Let us start with the auto trigger which triggers whenever a new email arrives at the configured user’s inbox. Here we have configured the trigger actions with some more options explained below. We can also use other options like export email only with attachments, emails having particular subject etc.

  • Folder: Inbox
  • To: User email addresses
  • Only with Attachments: Yes

Note: Since we have selected the option Only with Attachments as Yes, the flow will be triggered only if the email received has an attachment(s).

Apply to each – Looping the attachment(s)

Next action is use the Apply to each action to loop through all the attachments. The input to this action should be the Attachments output from the trigger.

The other actions mentioned below should be inside the Apply to each action which means for each individual attachment, we have to do the following action.

Get Attachment (V2) – Get the current attachment in the loop

The first action inside the Apply to each action should be the Get Attachment to get the current attachment in the loop. The input params to the action is as follows.

  • Message Id: Message Id from the trigger action ( triggerOutputs()?[‘body/id’] )
  • Attachment Id: The current attachment id in the loop ( items(‘Apply_to_each’)?[‘Id’] )

The above action will return the attachment as binary.

Create file – Create the attachment in Onedrive

Next action is to create the file with the content. The input to the flow is as follows

  • Folder: Specify the folder path to the store the attachments
  • File Name: You can use the same attachment name ( outputs(‘Get_Attachment_(V2)’)?[‘body/name’] )
  • File Content: Pass the binary contents ( outputs(‘Get_Attachment_(V2)’)?[‘body/contentBytes’] )

Enhancements or Readers Tasks

Below are some of the additional actions that can be added to the above flow to make it more functional.

  1. Create a new folder for each email with the email subject name as the folder name
  2. Make sure that you check whether the folder exists or not before creating the folder.
  3. Both the email and the attachments has to be stored inside the folder created above.
  4. If you receive different kinds of attachments in a single email, then separate the attachments in different folder based on the type or category of the attachment.

Conclusion & What’s next?

We have come to the end of the post. The flow that we learned above is very simple and the functionality we implemented is also very simple by just getting the email attachments to the root folder in Onedrive. Please try to complete the above tasks to get exprienced in Power Automate.

Please leave your comments and also let me know if you have any issues or any scenario that you want me to implement using Power Automate.

I hope you enjoy reading the post, see you soon in another post.

Cheers. Happy Flowing…

2 thoughts on “Power Automate – Export email attachments to Onedrive

  1. You might want to look at the additional parameters of your first step (when an email arrives (v2)). There now is an option below the Only with Attachment that asks if you want to include those attachments. This enhancement eliminates the need to include the loop.

    Like

    • Actually, I stand corrected. While I do have the include attachments, the other details including the loops apply. Great article that will come into play many times. Thank you!

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s