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…

5 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

  2. Hi,
    This flow works fine while saving the attachments of xlsx type. However, I was unable to save the attachment of . eml type or . msg type in one drive which is attached in the mail. Is there any way of achieving it?

    Like

    • Hi, even if you save the entire .eml or .msg email in Onedrive or SharePoint. While previewing the file, the attachments are not clickable for download or view. It is by design and thats why the flow saves the attachments separately.

      Let me know if you have any other queries.

      Like

      • Hi,
        Recently I have experienced a weird issue on the trigger ‘When an email is saved (v3). When an email contains the .eml file then it is not returning in the attachments section of the trigger output but the .msg extension is working without any problem. I think there is an issue with the trigger or by design it works like that.

        Like

Leave a Reply to Brian9 Cancel 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 )

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