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.

Thanks…

Check this out Use query parameters to customize responses - Microsoft Graph | Microsoft Learn
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 vb.net 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

@Palaniyappan
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.

1 Like

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.

2 Likes

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:
https://graph.microsoft.com/v1.0/me/messages?%24filter=subject 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

Regards
Srikanth Reddy
9949953319

“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?

1 Like

Hello,
You can use : “contains(from/emailAddress/address,‘example@gmail.com’)”

2 Likes

Hello ,

For received Time you can use :
“receivedDateTime ge 2021-07-18”
Date format : yyyy-MM-dd
ge means greater than or equal to

  • less than lt
  • greater than gt
  • less than or equal to le
  • greater than or equal to ge
1 Like

Hi, @levent.kurt

What if I want to use multiple email addresses in the same query? And If those email addresses are being read from Config file?

I’m having a problem specifically using “endsWith” to qualify the query.
When I try to use “endsWith”, I get the following error:

Get Mail - get email from EBI: Code: ErrorInvalidUrlQueryFilter
Message: The query filter contains one or more invalid nodes.

I can substitute “contains” or “startsWith” and I don’t get an error.

The query is:

"ReceivedDateTime gt “+dtCurrent.toString(“yyyy-MM-dd”) + " and startsWith(Subject, ‘The Job: EMAPMEND’) and endsWith(Subject, ‘completed with warnings’)”

I’ll use “contains” to get around the issue for now, but would appreciate someone looking into the issue.

1 Like