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

Retrieve email messages from Outlook

(0) ShareShare
ReportReport
Posted on by 98

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.

Screenshot 2024-02-27 155539.png
I have the same question (0)
  • Verified answer
    Riyaz_riz11 Profile Picture
    4,048 Super User 2026 Season 1 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 Moderator 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
    98 on at

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

  • CU14110159-0 Profile Picture
    98 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 Moderator 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
    98 on at
    Thanks for your reply and it worked
  • CU14110159-0 Profile Picture
    98 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 Moderator 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 592

#2
Valantis Profile Picture

Valantis 340

#3
11manish Profile Picture

11manish 284

Last 30 days Overall leaderboard