Determine the number of emails in a folder that meet set criteria


I have a process that reads emails and saves attachments, and another that uses the URLs contained within a email (no attachments) to retrieve PDFs.

I want to be able to count the following so that I can trigger the processes if the number returned is greater than 0.

  • Number of emails with an attachment
  • Number of emails without attachments AND received date is less than 3 days.

Are there any activities that allow queries to determine the above, and if so what would the query code look like?



In the loop where you’re going through the emails, you can do the following to check:

  1. Emails with attachment: CurrentMail.Attachments.Count > 0
  2. Emails without attachment AND received date is less than 3 days: CurrentMail.Attachments.Count = 0 And (Now.Date - CurrentMail.DateAsDateTime.Date).Days < 3)
1 Like

Hope you are using outlook

  1. "@SQL=""urn:schemas:httpmail:hasattachment"" = 1"
  2. "@SQL=""urn:schemas:httpmail:hasattachment"" = 0 AND ""urn:schemas:httpmail:datereceived"" > '" + Now.Adddays(-3).ToString("yyyy-mm-dd") + "'"


Hi . Before I get into the loop to process the emails I want to determine if there are any to process. I want to count the number of emails in the folder that meet the criteria and then process if the number is greater then zero. Is there a way to determine the number of emails before I get into the loop?

Hi @Anil_G . We are using Outlook 365. How do I run the SQL command? Is that part of an Assign Activity?

These are the filters when you use get outlook mail messages…as you are using outlook 365 …try this in the get mail activity properties filter option

  1. "HasAttachments eq true" - for attachments
  2. "hasAttachments eq false and receivedDateTime ge " + Now.Adddays(-3).ToString

Hope this helps

Cheers how are you querying for your emails? Using Outlook 365 and For Each Email activity?

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.