web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Save email attachment ...
Power Automate
Unanswered

Save email attachment to folder based on email sender

(0) ShareShare
ReportReport
Posted on by 18

We receive invoices into our outlook. I want to create a flow of when an email is received with in invoice, the attachment is saved to a SharePoint folder based on the email sender. 

 

I have a vendor folder in SharePoint, and within the folder, there is a folder setup for each vendor and then that goes to sub-folders for each year and month. 

Example Folder:

  • 1234 Vendor 1
    • 2021
      • 07-2021
      • 08-2021
  • 2333 Vendor 2
    •  2021
      • 07-2021
      • 08-2021
  • 3455 Vendor 3
    •  2021
      • 07-2021
      • 08-2021

I'm thinking of having an excel table setup with the vendor folder name in one column and the email address for those vendors in another column. The flow would read off the table to see which folder is associated with that email address and save the file in that folder based off the table.

 

I would then need it to go into the correct year and then the current month that the email is received and save it in there. 

 

File name = invoice# - mm-dd-yyyy (attachment received date)

 

Any ideas on how to set this flow up or better ways to accomplish this?

Categories:
I have the same question (0)
  • eric-cheng Profile Picture
    5,171 on at
    Re: Save email attachment to folder based on email sender

    Hi @georgemaka ,

     

    Give this a go.

     

    ericcheng_0-1629533844251.png

    1) Use a when a new email arrives trigger and ensure you tick include attachments.  I also initialized a variable to show you the outputs.  

    ericcheng_1-1629534434586.png

     

     

    2) Loop through each attachment.  You may also want to add a condition to exclude attachments  which are not your invoices e.g. email signature images etc.  You can use Attachment Content Type to determine this.

     

    ericcheng_2-1629534466627.png

     

    3) I used SharePoint and added a Get Items.  Use a filter to filter based on the the Title column

     

    ericcheng_3-1629534577512.png

    4) I've set the FilePath variable and added a compose to show you the output.  The formula you need is below.  Swap out the value in bold with your document library name.

     

    /document library name/@{items('Apply_to_each_2')?['Folder']}/@{formatDateTime(utcNow(),'yyyy')}/@{concat(if(equals(length(string(int(formatDateTime(addDays(utcNow(),90), 'MM')))),1),concat('0',int(formatDateTime(addDays(utcNow(),90), 'MM'))),int(formatDateTime(addDays(utcNow(),90), 'MM'))), '-', formatDateTime(utcNow(),'yyyy'))}

     

    ericcheng_4-1629534638398.png

     

    And the outputs

     

    ericcheng_5-1629534825400.png

    As mentioned, you need should add a condition to exclude email signature images and also add some logic to create your filename.   However, the above should get you 99% of the way there.  Your filename should use a concat() and @{formatDateTime(triggerOutputs()?['body/receivedDateTime'],'MM-dd-yyyy')} to get the received date in your date format.

     

    ericcheng_6-1629534839442.png

     

    --------------------------------------------------------------------------
    If I have answered your question, please mark my post as a solution
    If you have found my response helpful, please give it a thumbs up

    Connect on LinkedIn

     

     

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Tomac Profile Picture

Tomac 497 Moderator

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 477 Super User 2025 Season 2

#3
chiaraalina Profile Picture

chiaraalina 242

Last 30 days Overall leaderboard