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
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
Hey @rrrradfafwgvafv
In Power Automate Desktop there is no certain type of Action which can directly filter the Email.
Please follow the below steps -
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
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:
To have the date dynamic use Convert text to datetime -action to convert the date from the form to yyyy-MM-dd format.
Then use that variable to Get emails (V3) search query
Also specify the subject in the advanced
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
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
Base64 encoded text: %GetEmailsV3Response['value'][0]['attachments'][0].contentBytes%
Flow overall:
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/
eetuRobo
18
Super User 2025 Season 1
stampcoin
6
John_Mavridis
6
Microsoft Employee