Andrzej.Kniola October 03, 2016 11:37
Up, couldn’t get it to work either with all syntax variations I could think of.
Closest thing I’ve made to emulate is to get the emails and iterate over them checking the subject (MailItem.Subject returns a string which you can check with normal string comparisons). While this works, it’s definitely suboptimal.
The Filter property is based on the Find method of the Outlook Interop API:
As the documentation says, if you are trying to use the Find or Restrict methods with user-defined fields, the fields must be defined in the folder, otherwise an error will occur. “There is no way to perform a “contains” operation. For example, you cannot use Find or Restrict to search for items that have a particular word in the Subject field.”
So the solution Andrzej provided is the best workaround.
But when I try anything valid in DASL from UiPathStudio, it throws either a Condition is not valid or Cannot parse errors.
So there must be something specific to your implementation that does not allow valid DASL queries to work correctly.
I mean sure, usual case is to limit to unread and that limits the results greatly for the iteration (if any needed at all, just take them as they come), but still, if the functionality is there, it should work
PS> If it’s based on Interop.Outlook, why the return type is System.Net.Mail.MailMessage instead of Interop.Outlook.MailItem (which BTW has much more info, f.e. Importance and BodyFormat)?
PPS. If someone is wondering why the dates are so old - it’s because I didn’t sort the collection in any way before Find, nor apply any date filters. Either way it’s besides the question.
Hi… Thanks for your suggestion. But still am facing difficulty on how to use contains inside filter. My exact scenario what I was using is “[To] = ‘email@example.com’” and the address in my mailbox is ‘firstname.lastname@example.org’ and not like email@example.com.
I had similar issue. Everywhere they give you you the DASL filter for Subject. But what we need is for other fields as well (like from, to , cc etc). Please have a look at my post here for the solution that worked like a charm for me: