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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Save email attachments...
Power Automate
Answered

Save email attachments with the same subject into one folder

(0) ShareShare
ReportReport
Posted on by 22

Hello, I am trying to save email attachments from outlook into a particular folder based on the email subject name. I want to save all attachments from last week only. I just want to save email attachments with the same subject into one folder.

Breakdown

Loop through each email

1. Get email subjects

2. Use email subjects to create a folder

3. For each of the emails received in the previous week,

          If the email subject is equal to an already created folder name(with the same subject), save attachments

          Else create a new folder based on the subject name to save attachments.

 

The issues I'm facing are;

1. Some of the email subjects have characters that can't be used in naming folders.

2. I am not able to check emails from the current date till 7 days before.

 

Could anyone please help? @v-yamao-msft @AlanPs1 @KvB1 @v-yuazh-msft 

Thank you in advance.

  • VJR Profile Picture
    7,635 on at

    Hi @philkam 

     

    1. Some of the email subjects have characters that can't be used in naming folders.

    Yes there are some characters that are not allowed while creating files/folders.

    Below are the characters. Take the subject line. Replace these characters with an empty string %""% and then create the folder.

    VJR_0-1639450569823.png

     

     

    2. I am not able to check emails from the current date till 7 days before.

     

    Currently since there is no direct method to get the emails within a specific date range, you can retrieve all the emails and then get the email date. Compare it to see if it is within the last 7 days.

     

    VJR_2-1639451296471.png

     

    If yes, then get the attachments.

     

    (Below is just an example for a messagebox which shows list of variables)

     

    VJR_3-1639451528777.png

     

     

     

     

     

  • philkam Profile Picture
    22 on at

    @VJR  I have been able to solve the issues I was having. Thank you so much for the quick response.

    How do I now save attachments to a specific folder?

     

    For each of the emails received in the previous week,

    If the email subject is equal to an already created folder name(with the same subject), save attachments

    Else create a new folder based on the subject name to save attachments.

     

    How would you recommend I execute this?

  • VJR Profile Picture
    7,635 on at

    Hi @philkam 

     

    Once you get the email subject and strip off the invalid characters (shown in point no 1 of my post above), then use "Folder exists" action. Video for Folder Exists

     

    If does not exists then create folder and save attachments.

    If exists then save the attachments

  • philkam Profile Picture
    22 on at

    Hi @VJR 

    Thank you for the video referral. It helped me a lot.

     

    I am adding a screencap of my process with a marker highlighting an issue on how to save the attachment . If the folder has already been created, how do I save the attachment in the else block?

    I noticed the retrieve emails will have the attachment already in a specified folder if I opted for the save attachments option.

    Thank you.

     

     

    IssuePDA.png

     

  • VJR Profile Picture
    7,635 on at

    Hi @philkam 

     

    I see what you mean.

     

    Since there is no direct option to download the attachments based on some condition you will need to do the below.

     

    - Allow all attachments to be downloaded into a "temporary" folder via the "Retrieve emails" action.

    - In your loop based on the subject check if the folder already exists.

    • If it exists then Move the attachment from the "temporary" folder to your "desired" folder.
    • If it does not exists then create the folder and Move the attachment.

    - Move files is available as an action in PAD.

    - You will get the path of temporary attachment folder along with the filename in the currentitem.attachments datatable variable

    - If you no longer need the temporary folder then delete it after the loop.

     

  • philkam Profile Picture
    22 on at

    Hello @VJR 

     

    If I have retrieved all the emails into a temporary folder, how then do I know that a particular file(like abc.pdf) was retrieve from an email(outlook email) with a particular subject( like invoice)?

    Does each retrieved attachment in the temporary folder have a link with the email subject from which it was retrieved from? Filenames might not always have the same name as the email subject.

    If attachments had the same filename as the email subject I could have compared the ".NameWithoutExtension" to the folder name and move the files but this is not the case.

     

    Thanks in advance.

  • VJR Profile Picture
    7,635 on at

    Hi @philkam 

     

    "how then do I know that a particular file(like abc.pdf) was retrieve from an email(outlook email) with a particular subject( like invoice)"

     

    Within the loop you will get all details using the currentitem.

    In the RetrievedEmails datatable there is subject as well as attachment path.

     

    Put a Display Message like I have shown above and you will come to know.

  • Verified answer
    philkam Profile Picture
    22 on at

    Hi @VJR 

    I have finally figured it out. I think my confusion was coming from the fact that the attachments were stored in a list. Thank you so much for your patience.
    I am posting a screencap of the final solution to help the community in case anyone encounters such a problem.

     

    Save email attachments with the same subject into one folderSave email attachments with the same subject into one folder

     

  • VJR Profile Picture
    7,635 on at

    Ok, good to know it worked out as expected.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 292 Super User 2026 Season 2

#2
Henil Profile Picture

Henil 128

#3
anirudhev Profile Picture

anirudhev 124

Last 30 days Overall leaderboard