Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Triggers
  • Resources
  • ABOUT ME
  • Get help with your flow
Menu

How to process .zip email attachment in Power Automate

Posted on October 9, 2022October 9, 2022 by Tom

“I receive an email with a .zip file in the attachment, can I extract its contents before Power Automate saves it into SharePoint?”


Power Automate is a great tool to help you organise email attachments. Every time you receive an email, it can check if it contains an attachment, and store it in a specific location. But for attached .zip files it’s not enough. You don’t want to just save the .zip file as you can hardly use it before you extract it. Just saving it will need a manual work to extract it – not the ideal situation. Why not let the flow do this work?

Extract the .zip file

Before you can extract the file, you must store it somewhere, e.g. in OneDrive or SharePoint. Just save it as you’d save any other attachment.

As there can be more than one attachments, check if the attachment ends with .zip in a ‘Condition’. If it does, extract it with the ‘Extract folder’ action.

It’ll ask you for the location of the file (which you know since you just created it), and a folder where it should extract the files. You can’t extract them directly into a SharePoint library, you must always create a new folder for the files, e.g. using the current date/time.

Important note: the action seems to have problem with : character in the time! I recommend using a custom format without the colon:

utcNow('yyyyMMdd-HHmmss')
Power Automate zip email attachment

Move the files into a common folder

The files are now extracted, but in their own folder. That’s not a good place unless you plan using a wild folder structure. But since they’re now stored in SharePoint, you can move them anywhere you want.

Add the ‘Move file’ action and move the files using their Id in the final location. A fixed one, or a different location for each file.

Cleanup the .zip file and the folder

At this moment the flow created a lot of mess. You have the extracted files in the desired location (good!) but you’ve got also the .zip file and the empty folder (bad). Since you probably don’t want to keep all of it, you should do a cleanup.

Deleting the .zip file is the easier task – add the ‘Delete file’ action and delete it. You already have the file Id as you created the file a few steps before.

The much more complicated task is deletion of the folder. Since Power Automate doesn’t have a dedicated action to delete folders, you must use a “workaround”.

Firstly, you must get the Id of the folder as it’s not among the outputs of ‘Extract folder’.

Add an extra ‘Compose’ action to store the folder name before you extract the files. The reason is that the folder name is using the current date/time – it’d be different after the ‘Extract folder’ action.

Power Automate zip email attachment

Once you know what folder name was used, add ‘Get files (properties only)’ with a Filter query on the folder path. You already moved all the files from the folder so it’ll return just 1 item – the folder itself.

substringof('@{outputs('Compose')}', FileRef)
Power Automate zip email attachment

The folder itself can then be deleted using the ‘Delete item’ action. Enter the site URL, type in the library name (it won’t be in the dropdown), and use the returned Id to delete the folder.

The whole flow

Power Automate zip email attachment

Summary

When you build a Power Automate flow, you should always think about the next step to automate – you just saved the email attachment, but what about the .zip files? If you just save them then somebody will have to extract them. Why don’t you automate also this “next step”? And when the flow extracts them, somebody has to do the cleanup – what about this step? And the next one, and the next one…?


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

3 thoughts on “How to process .zip email attachment in Power Automate”

  1. Pingback: Low code/no code:如何用Power App建立PDF/原生不用瀏覽器/Power Automate自動解壓縮附件 - 口吃、閱讀筆記、雲端運算、資料分析:中途筆記
  2. Noah Davis says:
    December 8, 2022 at 7:51 pm

    The .zip file I receive is password protected, requiring a password before the file will expand the contents. Any tips on how to solve for that?

    Any guidance would be great. Thank you.

    Reply
    1. Tom says:
      December 15, 2022 at 1:43 pm

      Hello Noah,
      not really, I never did this for password protected files.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


There's also the HTTP requests to SharePoint cheat sheet to help you overcome limitations of some standard actions!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

  • How to find Excel rows missing in SharePoint list (Power Automate)March 29, 2023
  • Check whether user exists in AAD with Power AutomateMarch 26, 2023
  • How to highlight whole SharePoint row based on calculated dateMarch 22, 2023
  • Why is your Power Automate flow running so slow?March 19, 2023
  • How to add multiple links to the Power Automate approval taskMarch 15, 2023

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes