Microsoft Office 365 - Get Mail Activity Queries to filter returned emails

Hello UiPathCommunity,

Microsoft announced that, effective October 1, 2022, They will begin to permanently disable Basic Authentication in Exchange Online in all tenants, regardless of usage, with the exception of SMTP Auth. as Basic Authentication is an outdated industry standard.

Its time to use Microsoft implementation of Modern Authentication (OAuth), which is the newer and more secure version of authentication to Microsoft platforms. We can achieve this in UiPath using Microsoft Office 365 activities.

To enable the Microsoft Office 365 activities, your app must be integrated with the Microsoft identity platform and have the correct Microsoft Graph API permissions assigned to it. Please check the below thread and configure the same in your Organization.

Here, we need to pass the query for filtering returned emails.

Note: All Microsoft Office 365 activities should be inside Microsoft Office 365 Scope activity.

Below are the queries used for filtering the returned emails using Get Mail activity.

1. Get Emails with Subject contains particular text

               "contains(subject, 'subject you are looking for')"

2. Get Emails with Subject Equals to particular text

               "subject eq 'subject you are looking for'"

3. Get Emails with Subject starts with particular text

               "startsWith(subject, 'subject you are looking for')"

4. Get Emails with Subject ends with particular text

               "endsWith(subject, 'subject you are looking for')"

5. Get Emails with Body contains particular text

               "contains(body/content, 'body you are looking for')"

6. Get Emails with Body Equals to particular text

               "Body eq 'body you are looking for'"

7. Get Emails with Body starts with particular text

               "startsWith(body/content, 'body you are looking for')"

8. Get Emails with Body ends with particular text

               "endsWith(body/content, 'body you are looking for')"

9. Get Emails from specific recipients

               "contains(from/emailAddress/address, 'EmailID')"

10. Get Emails if received date is greather than particular date

               "receivedDateTime gt yyyy-MM-dd"

11. Get Emails if received date is less than particular date

               "receivedDateTime lt yyyy-MM-dd"

12. Get Emails if received date is greather than or equal to particular date

               "receivedDateTime ge yyyy-MM-dd"

13. Get Emails if received date is less than or equal to particular date

               "receivedDateTime le yyyy-MM-dd"

14. Get Emails with Subject contains particular text and body contains particular text

               "contains(subject, 'subject you are looking for') and contains(body/content, 'body you are looking for')"

15. Get Emails with Subject contains particular text or body contains particular text

               "contains(subject, 'subject you are looking for') or contains(body/content, 'body you are looking for')"

16. Get Emails with Subject Not equals to particular text

               "subject ne 'subject you are looking for'"

17. Get Emails with Body Not equals to particular text

               "Body ne 'body you are looking for'"
11 Likes

Great compilation of Query to get emails…

1 Like

Thanks for the feedback bro @prasadsatish

Hi ,

Thank you for the compilation.

My subject is stored in a variable “Email_Subject”.

Can you help me how can I filter that using contains?
I want to use it to filter each email using this activity.

Also I used –

“subject eq '”+ Email_Subject +“'”

to filter my emails.But its failing in unattended mode with Get Mail access denied message even though the authentication type is set to ‘Application Id and Secret’ and its working if I keep the filter blank.It is working in attended mode with ‘Interactive token’ as the authentication type!

Can you please help with your insights here?
I want to try with contains now to see if that works.

Please let me know how do I place a variable here -

Regards,
G

@gokul1904

Hope you setup Account properly in Microsoft Azure and you have enough credentials to access Office 365.

If yes then set Authentication Type to UsernameAndPassword pass the credentials under Username and Password (Unattended) section.

Thank you for this guide.

Explain this to me, how do you find this parameter?

Because I was using the methods of the office365message variable and it didn’t arrive in this combination.

@GCaldas

Try to update Microsoft Office 365 package and check it once.

Let me try to explain a little better :).

I want to understand how you identified this attribute.
While I can use “contains(subject, ‘test123’)” and it works.

So, I can get the ‘from’ with mailMessage(0).from .
I was using “contains(from, 'test123)” and of course I got an error.

Your solution works.

Hey @lakshman

Great post and thanks for sharing.

An additional mail filter example you can use for checking attachments also:
contains(subject,‘subject you are looking for’) and (hasAttachments eq true)

Cheers

Steve