Get Outlook Mail Message Advanced Filter Criteria

I am trying to find an optimized and clean solution for filtering mail messages using the ‘Get Outlook Mail Message’ activity with the filter option. e.g., I want to filter with below criteria

(Subject: ‘MySubject’) And (Email from: ‘email1’ Or ‘email2’) And (Has Attachment)

This is what I have and is working for me:
“@SQL=(” + “”“” + “urn:schemas:httpmail:subject” + “”“” + " like ‘%MySubject%’) and (" + “”“” + “urn:schemas:httpmail:fromemail” + “”“” + " like ‘%LastName1%’ or " + “”“” + “urn:schemas:httpmail:fromemail” + “”“” + " like ‘%LastName2%’) and (" + “”“” + “urn:schemas:httpmail:hasattachment” + “”“” + " = ‘true’)"

I am trying to resolve/Optimized,

  1. Instead of Last Name use email. (It is not working for me with the email)
  2. Make the Name and Subject variables driven

Maybe the new UiPath ML component will eliminate or optimized the solution in the future.

**Anyone looking for Advanced Filter Criteria on Mail Messages, can use the above solution **


I would also like to get any help on adding attachment Name/Extension criteria. I tried following with no luck,

“@SQL=” + “”“” + “urn:schemas:httpmail:attachmentfilename” + “”“” + " like ‘%FileName%’"

Hi @atul.trikha,

This looks helpful , would appreciate if you can please share the uipath code snippet for same .

Mukesh (13.5 KB)
Please find the attached workflow in Zip file.


Thank you !

hi guys,

I want to find the attached file in outlook. The mailbox I work with contains 30,000 mails. So I get a timeout error. I saw the flow you developed. How can I run this stream for the attached file name.

You can add “urn:schemas:httpmail:attachmentfilename” condition in the above query to add attachment file name criteria.


Thank you! after i try this method i will writing result.

Hi there,

Thanks for all the info above. Just a little note:

  • To use the filter, it has to be put into a variable instead of putting the whole text into the filter option (it doesn’t work until I put the filter statement into a variable, and put the variable into the filter option)
    To make it as variable: replace %MySubject% to %“& variable &”%in the statement
    List item
1 Like


For the email, I have tried many different combinations “urn:schemas:httpmail:xxx" where from xxx I tried email, mail, sender, senderemail, senderemailaddress and none of them worked for me. I took me several days to find the answer.

I was only able to get it with this sentence. Just copy and paste and change the email.

“@SQL= ““”” like ‘’”

If you want to use a variable instead of a fix value. Define it before the GET OUTLOOK MAIL activity with an ASSIGN Box and named it for later use (I used EmailDe as the name of my variable)

Then inside the filter just replace the with the following… where you can see I cut the string after the first % with a " then I concatenate it with + EmailDe + and open again the string with a " to be able to finish with a % then a ’ and then a "

“@SQL= ““”” like '%”+EmailDe+“%'”

If you want to add new conditions just do not close the string with a " and just add an AND… and remember to close the whole string with a "

Here you have an example where I check the sender email, and if the subject contains a string I previously add in a variable named Codigo and if the email has attachment. I have seen that you are using TRUE but that didn’t worked for me either and I use =1.

“@SQL= ““”” like '%”+EmailDe+“%’ and urn:schemas:httpmail:subject like '%”+Codigo+“%’ and urn:schemas:httpmail:hasattachment=1”

Hope it helps!