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

We’re using Microsoft Office 365, Get Mail activity to retrieve the mails from an account created specifically for the robots.
Each robot handles specific mails based on the mails’s titles.
There’s Query property of Get Mail activity that allows us to filter the retrieved mails.
The issue that this property only accepts “eq” (equal) operator. For example, using the following value of the property works fine:
“subject eq ‘Progress AP Invoice of APR-2019’”
Trying to use operators like “contains”/“startswith” instead of eq, all fails.
We need to be able to do something like “subject contains ‘Progress AP Invoice’” or “subject startswith ‘Progress AP Invoice’”.

I know I can retrieve all the mails and later one check the subject if contains the value we need or not. But this solution we require that all robots to process all mails and all the actual steps of the robot to do will be basically inside if condition.

So, is there a way to use any operator to check substring of the mail subject using the Query property.


Check this out
It has the query keywords you can/cant use.

Your other workaround is just checking on each email if it satisfy your condition using if activity which is not the best option when your mail list is large.

Thanks @Emman_Pelayo for your reply.
I’ve checked it before, but the list doesn’t include operator that would solve my issue.
I was hoping there may be around around using VB.Net script for something like that.

I haven’t tried connecting to office365 yet but you can try to convert the Office365Message[] return type of the get mail activity to a datatable/List first. With that, you can easily use script for your mail list.

It will be the same, I’ve to go through all the mails.
I was hoping to find around of this.
Anyhow, thanks for your reply.

What is the query when we want to filter emails with subject that contains a keyword/
For example : I want to filter all emails that contains subject = ‘Test’
Mail 1 subject : ‘Test1’
Mail 2 subject : ‘Test2’
Mail 3 subject : ‘Test3’

In outlook mail activity mention this expression in filter property
“@SQL=urn:schemas:httpmail:subject like ‘%Test%’ “

Cheers @MariaJosephina

It is not working.
getting the error :

Get Mail: Code: BadRequest
Message: Invalid filter clause
Inner error

I am asking about the Get Mail activity of office 365 scope.

lstMails.AsEnumerable.where((function(x) x.Sender.Address= In_FromAddress and x.Subject=In_Subject)).tolist

try this

In GetMail -> Properties -> Query, write “startswith(subject,‘Test’)”. It is working for me.

What about if we need to filter based on email sender and email received datetime.

1 Like

For Office 365 Activities use only filter in graph API query parameters

Example: eq ‘let’‘s meet for lunch?’

In UiPath just use it as:
“subject eq ‘let’‘s meet for lunch?’”

Graph API query Parameters available here:

Hi ,

Did you got answer, if yes please share it with me. I’m also looking for the answer

Srikanth Reddy

“subject eq '”+TextInput+"’" is not working.
Getting BadRequest error.
What is the correct format to use for Query in Get Mail activity (Microsoft Office 365 scope)?

This should work:

“subject eq '”+inputMail+"’"

Yes it is resolved. What kind of issue you are facing with filters?