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 / Save attachments from ...
Power Automate
Unanswered

Save attachments from Email

(0) ShareShare
ReportReport
Posted on by

Hi Experts

 

I would like to save all attachments from the outlook base on the subject title.

But since the PR number is random, please advise how to input it in the "subject contains".

 

Thank You

 

Cityenergy_3-1718873243159.png

 

 

Cityenergy_2-1718872997182.png

 

 

 

 

 

 

 

I have the same question (0)
  • eetuRobo Profile Picture
    4,204 Super User 2025 Season 2 on at

    What if you used the starting two words "Purchase Requisition" in the Subject contains field? Or can there be other emails with that text that you would not want to retrieve in the flow?

    If that's not specific enough and there can be emails that has "Purchase Requisition" at the subject line then I would add something to "Body contains". So if the body will always have "Purchase Requisition XXXXXX has been approved. Here is the PDF for that Purchase Requisition" then add the "has been approved. Here is the PDF for that Purchase Requisition" to the Body contains field. Then I think it should be pretty sure that it will only trigger when purchase requisition has been approved.

    eetuRobo_0-1718876632123.png

     

  • Cityenergy Profile Picture
    on at

    Actually, the keyword is [Purchase Requisition] and [has been approved.] But i'm not sure how to input in the 'subject contains' in PAD and it will not be able to retrieve the attachments since the numbers are missing.

     

  • eetuRobo Profile Picture
    4,204 Super User 2025 Season 2 on at

    Do you mean that it needs the square brackets? If so just write them in it.

    Or do you mean that you want it to check that the subject line contains BOTH Purchase Requisition AND has been approved.?
    If so then you either use just one and then specify the email with some other field like Body contains like I suggested. The Subject contains cant have both starting and ending as far as I know since its just a "Contains". So the contains text has to be all together.

    If you really need to use the subject contains then I think you first have it check the "Purchase Requisition" and then have condition that checks if the subject ends with "has been approved" (you need to loop each email)

    eetuRobo_0-1718877406820.png

     

     

  • VishnuReddy1997 Profile Picture
    2,656 Super User 2025 Season 2 on at

    Hi @Cityenergy ,

     

    If mail contain first two words Payment Requisition everytime,you can configure as shown below.

    VishnuReddy1997_0-1718877419126.png

     

    (Note:- if you got your solution you can mark as solution and gives kudos)


    Thanks & Regards

    Vishnu Reddy

     

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

    Hi @Cityenergy !

     

    Try out this flow.

    NathanAlvares24_2-1718877742397.png

     

    Initially for the first Retrieve email messages, here is what it looks like:

    NathanAlvares24_1-1718877503577.png

    I will not save the attachments initially, just retrieve those email messages with that Subject 'Purchase Requisition'

     

    Next I use a loop for each retrieved email. In that a condition i use, expression is this:

     

     

     

     

    %Contains(RetrievedEmail.Subject, 'Purchase Requisition',True) AND Contains(RetrievedEmail.Subject, 'has been approved',True)%

     

     

     

     

    Since these 2 are keywords.

     

    Then i use Crop text to get the PR Number. Trim for any whitespaces.

    then again use retrieve email messages action. This is for the second one:

    NathanAlvares24_3-1718877828067.png

    Here i specified in the subject field to fetch only that which matches and save the attachments to a folder. And also mark as read after doing this.

     

    Input:

    NathanAlvares24_0-1718878084545.png

     

    Output:

    NathanAlvares24_1-1718878137445.png

     

    Code(Copy and paste the below code into your power automate desktop):

     

    Outlook.Launch Instance=> OutlookInstance
    Outlook.RetrieveEmailMessages.RetrieveEmails Instance: OutlookInstance Account: $'''test@hotmail.com''' MailFolder: $'''Inbox''' EmailsToRetrieve: Outlook.RetrieveMessagesMode.Unread MarkAsRead: False ReadBodyAsHtml: False FromContains: $'''test@hotmail.com''' SubjectContains: $'''Purchase Requisition''' Messages=> RetrievedEmails
    LOOP FOREACH RetrievedEmail IN RetrievedEmails
     IF (Contains(RetrievedEmail.Subject, 'Purchase Requisition') AND Contains(RetrievedEmail.Subject, 'has been approved')) = $'''True''' THEN
     Text.CropText.CropTextBetweenFlags Text: RetrievedEmail.Subject FromFlag: $'''Purchase Requisition''' ToFlag: $'''has been approved''' IgnoreCase: False CroppedText=> PRNumber IsFlagFound=> IsFlagFound
     Text.Trim Text: PRNumber TrimOption: Text.TrimOption.Both TrimmedText=> PRNumber
     Outlook.RetrieveEmailMessages.RetrieveEmailsAndSaveAttachments Instance: OutlookInstance Account: $'''test@hotmail.com''' MailFolder: $'''Inbox''' EmailsToRetrieve: Outlook.RetrieveMessagesMode.Unread MarkAsRead: True ReadBodyAsHtml: False FromContains: $'''test@hotmail.com''' SubjectContains: $'''Purchase Requisition %PRNumber% has been approved''' SaveAttachmentsInto: $'''C:\\Users''' Messages=> RetrievedEmails2
     ELSE
     NEXT LOOP
     END
    END
    Outlook.Close Instance: OutlookInstance

     

     

    Just replace your Attachment path and Email IDs for fields To and From in this code.

     

    I hope this helps.

  • Cityenergy Profile Picture
    on at

    Hi @NathanAlvares24 

     

    My 'if' Actions have lesser statement as yours.

    Are you able to advise?

     

    Thank You

    Cityenergy_0-1719037215259.pngCityenergy_1-1719037383735.png

     

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

    Hi @Cityenergy !

     

    In the first operand write this:

     

     

     

    %Contains(retrievedemail.Subject, 'Purchase Requisition', True) AND Contains(retrievedemail.Subject, 'has been approved', True)%

     

     

     

    In the second operand write this:

     

     

     

    True

     

     

     

    And finally in the operator dropdown, select the option: "Equal to (=)"

     

    So therefore it will look something like this:

    NathanAlvares24_0-1719039255945.png

     

    I hope this helps.

  • Cityenergy Profile Picture
    on at

    Hi @NathanAlvares24 

    Thank You so much!

    I have retrieved the attachment successfully and also learned something new.

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 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard