“I’ve got a dedicated mailbox collecting emails with various attachments. Can I use Power Automate to save them from the email to a specific SharePoint folder based on the attachment type?”
One of the basic use cases for Power Automate is to save attachments from incoming emails. You receive an email in your mailbox and it’ll automatically store it to OneDrive or a SharePoint site. But with the basic solution it’ll save all the attachments to one place. That’s still a lot of work for you to organise them later.
Wouldn’t it be nice if you could automate also this step? To save the attachment in a specific folder based on its type?
Create a configuration list
As explained in a previous article, you don’t want to put the folder configuration directly into a flow. You want to keep the attachment-folder configuration outside of it, in a configuration list. And that’s the first step – create a configuration list in SharePoint. The list needs just 2 columns, the file type (or some other part of the file name) and the folder.
Use it to get the file location
Now, with the configuration list in place you can start with the flow. Start with the trigger ‘When a new email arrives’, potentially with a trigger condition on attachments or email subject(s). Among the trigger outputs will be also the email attachments and their properties, including the attachment name.
The attachment name is important because that’s what the processing is based on. Extract the part that’s used in the configuration list, in this case the file extension…
last(split(items('Apply_to_each')?['name'],'.'))
… and use it in a lookup to the configuration list.
Save the file
The ‘Get items’ action will return one item from the configuration list, the one with the destination folder. Use it in the folder path in the ‘Create file’ action.
Don’t worry about the automatically added ‘Apply to each 2’. Since there’s only 1 entry in the configuration list for the file type it’ll always return only 1 item = it’ll run only once.
Summary
You can use Power Automate not only to save email attachments, but also to save each attachment in a specific folder. Firstly, create a configuration list based on a part of the file name. Secondly, parse the file name and use it to lookup the config list. Finally, once you have the folder from the config list, use it to store the file in the right folder.
The benefit of using a configuration list is that you can easily add another type/folder configuration. Just add them to the configuration list and flow will take care of the rest, including creation of the folder(s).