Site icon Kaizen.Personal computer work.

Specify date range to retrieve mail. (Power Automate Desktop)

Japanese version.

Currently, there is no date range item in the email filter.

As an alternative, this article will show you how to specify conditions by date in the email.

The premise is that it is not possible to filter at this point of acquisition.

This is achieved by performing conditional judgment on the acquired e-mail.

Overall view of Flow

Robin(for copy and paste)

Can be copied and pasted into Power Automate Desktop.

For Outlook.

Outlook.Launch Instance=> OutlookInstance
Outlook.RetrieveEmailMessages.RetrieveEmails Instance: OutlookInstance Account: `` MailFolder: $'''INBOX''' EmailsToRetrieve: Outlook.RetrieveMessagesMode.All MarkAsRead: True Messages=> RetrievedEmails2
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateOnly CurrentDateTime=> CurrentDateTime
DateTime.Add DateTime: CurrentDateTime TimeToAdd: -1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> ToDate
DateTime.Add DateTime: CurrentDateTime TimeToAdd: -30 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> FromDate
LOOP FOREACH CurrentItem IN RetrievedEmails
    IF (FromDate <= CurrentItem.Date AND CurrentItem.Date <= ToDate) = True THEN
        # Place the action to be taken on the filtered email, and you are done
    END
END

Except Outlook.

Email.RetrieveEmails.Retrieve IMAPServer: `` Port: 993 EnableSSL: True Username: `` Password: `` AcceptUntrustedCertificates: False MailFolder: $'''INBOX''' MailsToRetrieve: Email.RetrieveMessagesMode.All MarkAsRead: True RetrievedEmails=> RetrievedEmails
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateOnly CurrentDateTime=> CurrentDateTime
DateTime.Add DateTime: CurrentDateTime TimeToAdd: -1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> ToDate
DateTime.Add DateTime: CurrentDateTime TimeToAdd: -30 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> FromDate
LOOP FOREACH CurrentItem IN RetrievedEmails
    IF (FromDate <= CurrentItem.Date AND CurrentItem.Date <= ToDate) = True THEN
        # Place the action to be taken on the filtered email, and you are done
    END
END

Procedure

The first step is to set up "Retrieve email messages Action".

If the incoming e-mail is an e-mail address registered in Outlook,

This will replace "Launch Outlook" and "Retrieve email messages from Outlook".

Ideally, you should be able to filter out as many messages as possible in this optional mail filter (other than by date).

Next, prepare the search range in a date/time variable.

The date range depends on the purpose, but in this example, the condition is 30 days before the day before the current date and time.

Get "Get current date and time" is used to get the "Current date only".

Next, set up two "Add to datetime" to create variables for the previous day and the date 30 days prior. (The name of the variable to be generated is arbitrary.)

ParameterPrevious day30 days prior
Datetime%CurrentDateTime%%CurrentDateTime%
Add-1-30
Time unitDaysDays
Name of variable produced%ToDate%%FromDate%

Then place a For each and specify %RetrievedEmails% as the "Value to iterate".

Place an "If" in "For each".

ParameterValue
First operand%FromDate <= CurrentItem.Date AND CurrentItem.Date <= ToDate%
OperatorEqual to (=)
Second operand%True%

Finally, in the "If", place the action to be taken on the filtered email, and you are done.

For those who want to learn Power Automate Desktop effectively


The information on this site is now available in an easy-to-read e-book format.

Or Kindle Unlimited (unlimited reading).

You willl discover how to about basic operations.

By the end of this book, you will be equipped with the knowledge you need to use Power Automate Desktop to streamline your workflow.

Links

Tips(Power Automate Desktop)

Exit mobile version