Skip to main content

Notifications

Community site session details

Community site session details

Session Id : +k+lcdCF08G3Ov+M+iH4Np
Power Automate - Power Automate Desktop
Unanswered

Filter email by receive date using power automate desktop

Like (2) ShareShare
ReportReport
Posted on 8 Jul 2024 14:23:51 by 108

Hi All,

 

I get an email every day with the same subject, 1 email a day. I've put them all in one folder. i created a custom form in the beginning of my flows that requires to input a received date. So now i want to retrieve the email by the specific received date and i want to save the email attachment to my local drive.


Anyone can help me with this? many thanks

  • mathiaskjeldsen Profile Picture
    222 on 09 Jul 2024 at 16:21:42
    Re: Filter email by receive date using power automate desktop

    Hey @rrrradfafwgvafv 

     

    You need to set a variable with the date and use that as reference in the flow afterwards. You do that by using Get Current Date and Time and converting it afterwards to the format needed. Then when you get to the email filter, you use that variable as input to which email to open. I explained the first part of it here, if you are confused on how to get it to work.

     

    Automate Excel File Opening with Data-Driven Flows in Power Automate Desktop

     

  • Sayan Profile Picture
    694 Super User 2025 Season 1 on 09 Jul 2024 at 04:53:04
    Re: Filter email by receive date using power automate desktop

    Hey @rrrradfafwgvafv 

    In Power Automate Desktop there is no certain type of Action which can directly filter the Email.

     

    Please follow the below steps -

     

    Sayan_0-1720469463377.png

     

    Also Copy and Paste this code just made some necessary changes It will work

     

    SET Date TO $'''08-07-2024'''
    Outlook.Launch Instance=> OutlookInstance
    Outlook.RetrieveEmailMessages.RetrieveEmailsAndSaveAttachments Instance: OutlookInstance Account: $'''sayan.patra@xyz.com''' MailFolder: $'''Inbox''' EmailsToRetrieve: Outlook.RetrieveMessagesMode.All MarkAsRead: True ReadBodyAsHtml: False SubjectContains: $'''Documents''' SaveAttachmentsInto: $'''C:\\Users\\SayanPatra\\Documents\\IPRU''' Messages=> RetrievedEmails
    LOOP FOREACH CurrentItem IN RetrievedEmails
    Text.ConvertDateTimeToText.FromDateTime DateTime: CurrentItem.Date StandardFormat: Text.WellKnownDateTimeFormat.ShortDate Result=> FormattedDateTime
    IF FormattedDateTime = Date THEN
    IF IsNotEmpty(CurrentItem.Attachments) THEN
    LOOP FOREACH Attachment IN CurrentItem.Attachments
    File.Move Files: Attachment Destination: $'''C:\\Users\\SayanPatra\\Downloads''' IfFileExists: File.IfExists.DoNothing MovedFiles=> MovedFiles
    END
    END
    END
    END

     

    After that if the solution not work. Please share your workflow.

    ------------------------------------------------------------------------------------------------------------------------------

    If my suggestion helped you, please give it a Thumbs up and Mark it as a Solution so that it can benefit others in the community.

    Sayan Patra

    RPA Developer

    Follow me on LinkedIn 

     

  • eetuRobo Profile Picture
    3,273 Super User 2025 Season 1 on 09 Jul 2024 at 04:29:46
    Re: Filter email by receive date using power automate desktop

    Do you have premium license? If so I suggest using Office 365 Outlooks Get emails (V3) -action for this since regular Outlook retrieve email messages -action does not have date filter.

    Get emails (V3) has Search Query field where you can filter the date received like so:

    eetuRobo_0-1720497673474.png

    To have the date dynamic use Convert text to datetime -action to convert the date from the form to yyyy-MM-dd format.

    eetuRobo_0-1720500380558.png


    Then use that variable to Get emails (V3) search query

    eetuRobo_1-1720497912579.png


    Also specify the subject in the advanced

    eetuRobo_2-1720498092470.png


    And since you said you get just one of those emails a day that has that subject then it should only receive one item.

    Then use Get Attachemnt (V2) to get that specific attachment. You get the message id and attachment id from the GetEmailsV3Response

    eetuRobo_3-1720498599893.png

    Message Id: %GetEmailsV3Response['value'][0].id%
    Attachment Id: %GetEmailsV3Response['value'][0]['attachments'][0].id%

    Then you can use Convert Base64 to file -action to download the attachment file to the folder you want

    eetuRobo_5-1720499370065.png

    Base64 encoded text: %GetEmailsV3Response['value'][0]['attachments'][0].contentBytes%

    Flow overall:

    eetuRobo_4-1720499242665.png



    If you don't have premium license or for some other reason need to use other than Office 365 Outlook -actions you have to loop all the messages to find correct date. So first you get all the emails with same subject and loop them all to find the one with the date from the form. That will be very time consuming though.


    Check this blog post for the idea:
    https://www.samurai-emblem.com/2023/08/03/power-automate-desktop-mail-filter-date-from-to/ 

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Power Automate Desktop

#1
eetuRobo Profile Picture

eetuRobo 18 Super User 2025 Season 1

#2
stampcoin Profile Picture

stampcoin 6

#2
John_Mavridis Profile Picture

John_Mavridis 6 Microsoft Employee

Overall leaderboard