One of the best ways to deal with email is not to deal with it at all. With Power Automate, you can check each email that arrives, and it fits a certain condition and automatically performs a specific action. Today I’ll explain how to save all attachments automatically when an email arrives.
Note: This post was inspired in finding a solution for the Power Automate Community because the obvious way of doing this will result in an error
The obvious way and why it won’t work
If you’re building this Flow, you would think you would only need 3 steps:
- When a new email arrives
- Apply to Each Attachment
- Save file.
- (Optional) move or archive the email
Since the trigger contains the attachments, you would build something like this.
But this will save invalid files of 4bytes each. The attachment object only returns the ID of the attachment, not the attachment itself.
I don’t know if this is intended, but it made me spend some time figuring out why the Flow was not working when the logic is 100% correct.
The solution is simple. You need to fetch the email by the ID you receive in the trigger, and then you’ll have the attachment object that you would expect.
The issue is quite a head-scratcher, but fortunately, it has a simple solution.
In the end, you can move the email using the “Move Email” action. With this, you will have one less email to process and avoid the tedious work to save all attachments from an email and archiving them.
This is the kind of automation we like. The one that does 100% of the work for us.