Power Automate – Export email attachments to Onedrive


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…


20 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.


    • 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!


  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?


    • 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.


      • 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.


  3. Hi Great Article. Easy to follow. Question: The signature of my email contains a number of images which also get extracted in addition to the attachment and saved to the root of Onedrive.Any way I can exclude those png images?


  4. Perhaps you can help me. I want to manually move emails from my office 365 inbox to other inbox folders depending on where i want their attachments saved in onedrive. I have spent hours. there does not seem to be a way to have the power automation work when the email has been moved to a folder rather than received in the inbox. Can you suggest anything?


    • Hi, using power automate the emails can be moved only when it reaches your inbox. From there you can move based on the subject or sender. Also, you can export the attachments as I had shown u in the blog. Can you please tell your requirement clearly so that I can see whether its feasible or not. You can email me at sudharsan_1985@live.in. Thanks.


      • Thank you. Amongst my emails, I have some that arrive with an application form attached. I want to move these manually to a mailbox folder i created called “application forms”. There is nothing in the emails that consistently identify them which is why i prefer to move them manually. When the emails are moved to the “Application forms” email folder, i want to use power automate to automatically save the attached forms to a folder in one drive. I thought this would be possible by setting the trigger to “ when email arrives” and using filter to select my “application forms” folder in inbox. However the automation does not work.


      • Hi Sudarshan- Only able to save .pdf and .doc attachments from the email received, also want to save .msg attachments from the email received. Is this possible or any workaround for this please?


  5. What do I need to do to save the attachments in a newly created a sub-folder for each email?

    So… email arrives.
    flow creates a sub-folder and saves the attachments in the sub-folder.
    the sub-folder is named with the current date/time.

    …or similar.



  6. Hi
    I’m having the same problem with saving a pdf using this flow. Where do you check the extensions given please as I couldn’t see that in your flow above.


  7. Hi Friends, to save the .msg file as an .eml file, you have to give the extension with the filename on the Create File method. Use this expression to concatenate the filename and extension.

    Please try the above and let me know whether it resolves your issues or not.


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 )

Facebook photo

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

Connecting to %s