How to write a query in UiPath.MocrosoftOffice365.Activities.Mail.Getmail to get conditioned emails

I tried to retrieve emails only with particular subject and received date. I used the following query and got an error:
“subject:”+in_Keywords +" AND received: >="+Convert.ToDateTime(Date.Now.AddDays(-1).ToString(“MM/dd/yyyy 21:00”)).ToString

What is the correct way to write a query in UiPath.MocrosoftOffice365.Activities.Mail.Getmail activity?

We assume O365 classic Get Mail

The filter syntax is about OData Filters


taken from:

ADDED: Additional Docu LINK to the Mail Properties:

Thanks.

I have modified my query to :
“subject eq '” + in_Keywords + “'” + " and receivedDateTime ge ‘" + Convert.ToDateTime(Date.Now.AddDays(-1).ToString(“yyyy-MM-dd 21:00”)).ToString + "’"

But got the following error:
Get Mail: Code: BadRequest
Message: Invalid filter clause: A binary operator with incompatible types was detected. Found operand types ‘Edm.DateTimeOffset’ and ‘Edm.String’ for operator kind ‘GreaterThanOrEqual’.
Inner error:
AdditionalData:
date: 2024-02-06T22:49:40
request-id: 7b2c9c98-9aeb-4bc2-b6b8-4b7fe762344e
client-request-id: 7b2c9c98-9aeb-4bc2-b6b8-4b7fe762344e
ClientRequestId: 7b2c9c98-9aeb-4bc2-b6b8-4b7fe762344e

In General you are on the right track. When this filter syntax is new to you, then we recommend to test it firstly with parts only:

  • test subject
  • test receiveDateTime
    then combine it

String.Format method can help you to make the variable injection more readable

it is about that the Date should not be treated as a string

e.g.

receivedDateTime ge 2022-05-23T11:59:59Z

we do not have used the surrounding ’

Kindly note:
Convert.ToDateTime(Date.Now.AddDays(-1).ToString(“yyyy-MM-dd 21:00”)).ToString

we can avoid a few unneeded redundant conversions
Now - is already a datetime we dont need to convert it to a string - parsing the string into a datetime and convert it into a string again

Now.AddDays(-1).ToString(… is sufficient

You are correct. I have modified the query to:

“subject eq '” + in_Keywords + “'” + " and receivedDateTime ge ‘" + DateTime.Now.AddDays(-1).AddHours(21).ToString(“yyyy-MM-dd HH:mm”) + "’"

But still got the same error

Hi,

How about the following? Probably it’s unnecessary to surround datetime by single quote.

"subject eq '" + in_Keywords + "'" + " and receivedDateTime ge " + DateTime.Now.AddDays(-1).AddHours(21).ToString("yyyy-MM-dd HH:mm")

Regards,

is similar to

@Yoichi rigth?

so @l.wang give a try and keep in mind that the UTC DateTime is to use
grafik

2 Likes

Thank you all!

I got it figured out. It was the format problem

Resolution:
“subject eq '” + in_Keywords + “'” + " and receivedDateTime ge " + DateTime.Now.AddDays(-1).Date.AddHours(21).ToString(“yyyy-MM-ddTHH:mm:ssZ”)

You are correct. I doesn’t need single quote

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.