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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Creating a folder and ...
Power Automate
Answered

Creating a folder and adding attachments received on mail to the created folder

(0) ShareShare
ReportReport
Posted on by 14

Hi,

 

When I get an email from a specific sender, I need the flow to automatically create a folder in Sharepoint based on subject of the mail and also save the attachments in the created folder.

 

All help is much appreciated

Categories:
I have the same question (0)
  • Verified answer
    NathanAlvares24 Profile Picture
    1,714 Moderator on at

    Hi @HeHo12345 !

     

    Try this flow.

    NathanAlvares24_0-1719579293017.png

    Flow function:

    1) It will get emails from a specific sender which needs to be specified in the From section of the trigger action, "When a new email arrives (V3)". Expand the advanced options to do that. Even put the yellow highlighted ones as 'Yes' since you need only attachments.

    Additionally for this trigger, I have added a trigger expression so as to only receive emails which do not have the subject as empty. Check below:

    NathanAlvares24_1-1719579562968.png

     

    NathanAlvares24_2-1719579591130.png

     

    NathanAlvares24_3-1719579633418.png

    Expression:

    @not(empty(triggerOutputs()?['body/Subject']))

     

    2) Then Create a new folder based on the subject name (from the trigger). Make sure that you already have a SharePoint document library in your SharePoint for this to happen. Also in the expression we make sure that it follows the rule of naming of folder convention. Like this: 

    NathanAlvares24_4-1719579791545.png

     

    NathanAlvares24_5-1719579847465.png

    Expression:

    replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(triggerOutputs()?['body/subject'], '"', ''), '*', ''), ':', ''), '<', ''), '>', ''), '?', ''), '/', ''), '\', ''), '|', ''), '&', 'and')

     

    3) Get the attachments from the mail since you can't just attach it directly to the folder. It will collect the data and use that data in the next action, Create file. This will loop through each attachment. See below:

    NathanAlvares24_6-1719580174245.png

     

    NathanAlvares24_7-1719580212489.png

     

    NathanAlvares24_8-1719580330050.png

    Input:

    NathanAlvares24_9-1719580440076.png

     

    Output:

    NathanAlvares24_11-1719580492207.png

     

    NathanAlvares24_12-1719580526684.png

     

    I hope this helps.

  • HeHo12345 Profile Picture
    14 on at

    It worked perfectly! Much appreciated.

     

    The subject of the mails can be quite long, is there a way that the whole subject wont show?

    Ex subject:

     xxxxxxx xxxx xxxxxx xxxxxxxxx x xxxx xxxxxx xxxx xxxx xxxxx xxxxxxxx (OSVC-240625081540371 / OSVL8FB2BD)

     

    The "x" mimics the number of letter typical in the subject. I would like that only "OSVL8FB2BD" to be showcased. This number/code is unique for each mail, and are always placed at the end after the dash in the paranthesis.

  • Verified answer
    NathanAlvares24 Profile Picture
    1,714 Moderator on at

    Hi @HeHo12345 !

     

    Instead of this:

    replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(triggerOutputs()?['body/subject'], '"', ''), '*', ''), ':', ''), '<', ''), '>', ''), '?', ''), '/', ''), '\', ''), '|', ''), '&', 'and')

     

    Replace with this code:

    trim(substring(triggerOutputs()?['body/Subject'], add(indexOf(triggerOutputs()?['body/Subject'], '/'), 1), sub(indexOf(triggerOutputs()?['body/Subject'], ')'), add(indexOf(triggerOutputs()?['body/Subject'], '/'), 1))))

     

    Output:

    NathanAlvares24_0-1719583776752.png

     

    I hope this helps.

  • HeHo12345 Profile Picture
    14 on at

    It worked perfectly, thank you so much!

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
Michael E. Gernaey Profile Picture

Michael E. Gernaey 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard