How to filter the out look messages on the current date

i was using out look message activity i want to get only all mails from yesterday date and from specific sender Example - all the mails sended by Ravi yesterday how to write the filter

@bpt.teja1996 Considering you already have the Output of Get Outlook Messages, say msgs, then you can use this :
msgs = msgs.Where(Function(x)x.Sender.DisplayName.Contains(“Ravi”) and Split(x.Headers(“Date”))(0).Trim.Equals(Now.AddDays(-1).ToString(“MM/dd/yyyy”)))

msgs will contain the filtered mail messages.

Try it and let me know if it didn’t work


Hi @supermanPunch i was new to UI path where i have to write that condition i have written subject = hrchanges it was filtering but i need the mails only from yesterdays

1 Like

@bpt.teja1996 Use an Assign Activity and assign in this way :

ListHRemails = ListHRemails.Where(Function(x)x.Sender.DisplayName.Contains(“Ravi”) and Split(x.Headers(“Date”))(0).Trim.Equals(Now.AddDays(-1).ToString(“MM/dd/yyyy”)))

If you have to filter by Subject, use the Filter Value in Subject else do not assign values to it.


EmailAutomation.xaml (12.0 KB)

hai @supermanPunch can you please edit the file i was not able to get you when i pasted it it was giving compailer error

@bpt.teja1996 What was the Error?


@bpt.teja1996 Just a Small Edit :sweat_smile:

At the End of the Statement use .ToList

@supermanPunch getting other error

@supermanPunch have you seen

@bpt.teja1996 Can you Show the Screenshot of the Statement that you have used in the Assign ?


@bpt.teja1996 You need to append ToList not ToString :sweat_smile:

sorry @supermanPunch i don’t get you exactly can tell me clearly

@bpt.teja1996 Use this :
ListHRemails.Where(Function(x)x.Sender.DisplayName.Contains(“Ravi”) and Split(x.Headers(“Date”))(0).Trim.Equals(Now.AddDays(-1).ToString(“MM/dd/yyyy”))).ToList


@supermanPunch when i was running i was getting this error

@bpt.teja1996 Use it after Get Outlook Mail Messages Activity.

thank you @supermanPunch but for coustamised day what is the expression i have to write suppose i want to get all the mails from april 4th for that what is the expression to write

@bpt.teja1996 Well, the Expression i suggested accepts a String value and hence you can replace Now.AddDays(-1).ToString(“MM/dd/yyyy”) with “04/04/2020” to match your Date value, but keep in mind the Date value which you provide should be in the Format “MM/dd/yyyy” as the other date in mail Headers is in this form.

Note :
Since the dates are String you cannot perform > or < operation only Equals


HI @supermanPunch but i was getting error message see . what are the changes should be done