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 / Retrieve email message...
Power Automate
Answered

Retrieve email messages from Outlook

(0) ShareShare
ReportReport
Posted on by 96

Hi 

 

I am using "Retrieve email messages from Outlook" action in PAD. For Subject contains field, I have 2 questions that need your help.

1) if I want to filter multiple conditions, how can configure this

2) if some word are fix and some are dynamic, how can I configure this using *

 

Thanks in advance.

I have the same question (0)
  • Verified answer
    Riyaz_riz11 Profile Picture
    3,891 Super User 2025 Season 2 on at

    Hi @zxky18 ,

    First Filter with fixed thing.

    And once you got mail try to use dynamic condition using if conditions inside or conditions. 

     


    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    Regards,
    Riyaz

  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,250 Super User 2025 Season 2 on at

    @zxky18 

     

    You cannot directly implement multiple filters in Outlook's subject field. However, after retrieving the emails in a list, you can iterate through them using a for-each loop and apply conditional statements, such as those outlined below, with either 'OR' or 'AND' conditions according to your needs.

     

    Deenuji_0-1709037775496.png

    Deenuji_1-1709037846019.png

     

     

    Code:

     

    Outlook.Launch Instance=> OutlookInstance
    Outlook.RetrieveEmailMessages.RetrieveEmails Instance: OutlookInstance Account: $'''deenu@abc.com''' MailFolder: $'''Inbox''' EmailsToRetrieve: Outlook.RetrieveMessagesMode.Unread MarkAsRead: True Messages=> RetrievedEmails
    LOOP FOREACH CurrentEmail IN RetrievedEmails
    IF (StartsWith(CurrentEmail.Subject, 'Hello', False) OR Contains(CurrentEmail.Subject, 'Hello Message', False)) = $'''True''' THEN
    Display.ShowMessageDialog.ShowMessage Title: $'''test''' Message: $'''test''' Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed
    END
    END

     

     

     

  • CU14110159-0 Profile Picture
    96 on at

    @Deenuji Hi Deenuji, thanks for your reply, I will try this solution

  • CU14110159-0 Profile Picture
    96 on at

    @Deenuji Hi Deenuji, thanks for your reply. how should I config in for-each loop if I want to download the attachment in the mail.

  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,250 Super User 2025 Season 2 on at

    @zxky18 

     

    Please follow the below screenshot and code. You can save your attachment by default during retrieve email messages from outlook and it will be saved on "C:\User\Documents" folder".

    Deenuji_1-1710925520290.png

     

     

    Flow Screenshot:

    Deenuji_0-1710925448260.png

     


    Please find the below code[Copy and paste the below code into you PAD designer and understand how it functioning):

     

    Outlook.Launch Instance=> OutlookInstance
    # By default all email will be saved in the config folder(C:\Users\Documents)
    Outlook.RetrieveEmailMessages.RetrieveEmailsAndSaveAttachments Instance: OutlookInstance Account: $'''Deenu@microsoft.com''' MailFolder: $'''Inbox''' EmailsToRetrieve: Outlook.RetrieveMessagesMode.Unread MarkAsRead: True ReadBodyAsHtml: False SubjectContains: $'''Product''' SaveAttachmentsInto: $'''C:\\Users\\Documents''' Messages=> RetrievedEmails
    LOOP FOREACH CurrentEmail IN RetrievedEmails
     IF (StartsWith(CurrentEmail.Subject, 'Hello', False) OR Contains(CurrentEmail.Subject, 'Hello Message', False)) = $'''True''' THEN
     Display.ShowMessageDialog.ShowMessage Title: $'''test''' Message: $'''Email with filtered subject''' Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed
     ELSE
     # If you email attachment doesn't contain your keyword then delete your attachments
     File.Delete Files: CurrentAttachment
     END
     LOOP FOREACH CurrentAttachment IN CurrentEmail.Attachments
     # If Attachment is .xlsx file then rename it with timestamp
     IF Contains(CurrentAttachment.Extension, $'''xlsx''', False) THEN
     DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
     Text.ConvertDateTimeToText.FromCustomDateTime DateTime: CurrentDateTime CustomFormat: $'''ddMMyyyy''' Result=> FormattedDateTime
     File.RenameFiles.Rename Files: CurrentAttachment NewName: $'''%CurrentAttachment.NameWithoutExtension%_%FormattedDateTime%%CurrentAttachment.Extension%''' KeepExtension: True IfFileExists: File.IfExists.Overwrite RenamedFiles=> RenamedFiles
     END
     END
    END

     


    New to power automate desktop? Not sure how to copy/paste the code. Please refer the below gif.

    Deenuji_2-1710925736957.gif



    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀. If you'd like to appreciate me, please write a LinkedIn recommendation 🙏

     
  • CU14110159-0 Profile Picture
    96 on at
    Thanks for your reply and it worked
  • CU14110159-0 Profile Picture
    96 on at

    @Deenuji, Hi Deenuji, I have another question may ask for your help since I am new in PAD, Can I loop each mail and download the attachment of the mail that in the one of subfolder in the inbox. I don't find appropriate action in PAD

  • Deenuji_Loganathan_ Profile Picture
    6,250 Super User 2025 Season 2 on at

    @zxky18 

    I apologize for the confusion. Could you please rephrase your question or provide further details about the scenario you're trying to accomplish?

     

    I've already provided a solution to loop through all emails and save them into a single folder with renaming. What are you aiming to achieve now? Are you interested in moving emails from the inbox to another folder?

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀. If you'd like to appreciate me, please write a LinkedIn recommendation 🙏

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