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 **

1 Like

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.

1 Like

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.

1 Like

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