cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
nedwards87
Frequent Visitor

Save email attachments based on attachment name

I am looking to create a flow that will save email attachments to specific folders based on their file names. I would like to set up an excel file or sharepoint list that will contain the information needed including the filename and the filepath where the file should be saved so that as i add additional filenames/folders, i dont have to modify the flow. 

So, if the attachment filename contains X0881 it would move it to a specific folder C:\data\881\

and if the filename contains X0904 it would move it to a specific folder C:\data\904\

and so on. 

 

Any thoughts?

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Re: Save email attachments based on attachment name

Hi @nedwards87 ,

 

If the files name are always in the same format, please try if the following way will work for you.

 

In this scenario, the file name will be the format likes “X0881Document”, I then get the key number 881 from the name and use it as the folder name. If a folder of name 881 already exists, the file will be created automatically, else, create the folder first, then create the file.

 

The function used in the Compose action:

 

substring(items('Apply_to_each')?['Name'],2,3)

 

 

 

An image for your reference:

1.PNG

 

Further, you could also try with what you’ve mentioned in your original post,, using an Excel or SharePoint list that contains the information needed including the filename, filepath. Then adding a condition to check if the attachment name contains the filename, if yes, create the file to the corresponding filepath.

 

Best regards,

Mabel

 

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
Super User
Super User

Re: Save email attachments based on attachment name

You can do this fairly simply, although I highly recommend avoiding an Excel file due to the many Excel Connector restrictions. A Visual Explanation of Flow Logical Expressions can get you started down the right path.

Basically you need to create a logical expression to check the attachment names of received emails, and if and when the match is met, it dynamically creates the matching subdirectory, and saves the file with a matching name.

This Modify Dynamic Content Before Use in Flow thread has a very similar request. 

 

nedwards87
Frequent Visitor

Re: Save email attachments based on attachment name

I have the logical expression down so that Flow can identify the email attachements based on the name, however, i am stuck on how to get flow to dynamically save the file to different folders based on theattachements filename. My initial though was to create a sharepoint list that contains the matching filenamename in one column and the folderpath where the file should be save in another column. 

Community Support
Community Support

Re: Save email attachments based on attachment name

Hi @nedwards87 ,

 

You may consider using Switch case in your flow.

 

If the file name contains X0881, then it goes to the action to create the file under folder  C:\data\881\.

If the file name contains X0904, then it goes to the action to create the file under folder C:\data\904\.

 

More details about Switch case for your reference:

https://flow.microsoft.com/en-us/blog/search-by-service/

 

Best regards,

Mabel

 

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
nedwards87
Frequent Visitor

Re: Save email attachments based on attachment name

This is how I currently have it configured but it is not ideal as we have more than 80 different files names right now and the case is limited to 27. The case method then requires cases within a case to get to 80. In the next few months we will be increasing to over 100 different filenames that the flow will need to process. This method is also extremely slow and when an email comes in with 8 attachments, it takes Flow about 10 seconds per attachment to process. 

Community Support
Community Support

Re: Save email attachments based on attachment name

Hi @nedwards87 ,

 

If the files name are always in the same format, please try if the following way will work for you.

 

In this scenario, the file name will be the format likes “X0881Document”, I then get the key number 881 from the name and use it as the folder name. If a folder of name 881 already exists, the file will be created automatically, else, create the folder first, then create the file.

 

The function used in the Compose action:

 

substring(items('Apply_to_each')?['Name'],2,3)

 

 

 

An image for your reference:

1.PNG

 

Further, you could also try with what you’ve mentioned in your original post,, using an Excel or SharePoint list that contains the information needed including the filename, filepath. Then adding a condition to check if the attachment name contains the filename, if yes, create the file to the corresponding filepath.

 

Best regards,

Mabel

 

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted
nedwards87
Frequent Visitor

Re: Save email attachments based on attachment name

Thanks for the reply. I have adopted your first solution for the time being. I do have a question, how would you reference the sharepoint list and pull the correspoding column for the filename?

Jfha97
New Member

Re: Save email attachments based on attachment name

Thank you for your response, it does help me solve part of a problem that I have right now. I thought about creating a new post, but this problem is very similar to the one I have.

 

I want to generate a flow that: 1. Gets attachments from specific email addresses; 2. Saves the attachments with a specific number given in the subject of the email. 

 

So overall I know how to create the flow based on the "Save Office 365 email attachments to OneDrive for Business" template. However, I do not know how to save the attachments given a specific parameter on the subject line.

 

Thank you in advance for your help!

Helpful resources

Announcements
firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Automate Community!

firstImage

Now Live: Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (8,128)