How to filter mails using Query property of Get Mail activity of Office 365

Thanks for the answer, any idea how can we add time along with the date. Any idea about the format?

Hey there, how can I also specify the time of day? I want to add a condition to only Get Mail on receivedDateTime < 11am today’s date.

This example retrieves all emails in inbox(or specified folder), that were sent today between 3:30:05 PM and 4:00:23 PM. (I have included seconds part to make a point).

  1. Store the ‘from’ and ‘To’ datetime ranges in a variable.
    fromDateTime = cdate(“11/15/2022 15:30:05”)
    toDateTime = cdate(“11/15/2022 16:00:23”)

  2. Add 6 hours to both variables since the date values are in UTC time.
    fromDateTime = fromDateTime.AddHours(6)
    toDateTime = toDateTime.AddHours(6)

  3. Apply filter as follows:
    Query = "receivedDateTime ge “+ fromDateTime.ToString(“yyyy-MM-ddTHH:mm:ssZ”)+” and ReceivedDateTime le "+ ToDateTime.ToString(“yyyy-MM-ddTHH:mm:ssZ”)

  4. in UiPath.MicrosoftOffice365.Activities.Mail.GetMail activity, set the following:
    Account = EmailAddress
    Mail Folder = inbox or any folder where you want to get your messages from
    Query =Query variable in Step 3
    Output = variable that will hold the results.

Now run the workflow. Add appropriate messages to see values. Example, print Query variable to see parameters used.

Can anyone help with retrieving mail body with contains?? for outlook 365?

Hello,

You can use :
“contains(body/content, ‘WordOrSentenceWhatYouSearch’)”

Hello Everyone, adding variable to the filter always give bad request error, saying that invalid filter clause. Would you share a filter with multiple condition that contains variable in it. Thank you

Hello Nurullah,

you can use the line like below for your issue.

“contains(Subject, '”+in_MailSubject+“') and receivedDateTime ge “+Today.ToString(“yyyy-MM-dd”) + " and (contains(from/emailAddress/address, '”+arr_MailFrom(0)+”') or contains(from/emailAddress/address, ‘“+arr_MailFrom(1)+”’) or contains(from/emailAddress/address, ‘“+arr_MailFrom(2)+”’))"

Hi,
do you know how to filter mails by “to” property?
image