How to filter email by day with c#

Hi, i would like to get outlook mails by yesterday on current day. i have fill as below but seems i missed something. May help to advise what is the correct code for get the filter 1 day before emails?

Hi @balaraj.pubalan

“[ReceivedTime] >= '” + DateTime.Now.AddDays(-1).ToString(“MM/dd/yyyy”) + “’ AND [ReceivedTime] < '” + DateTime.Now.ToString(“MM/dd/yyyy”) + “'”

Hope it helps!!

1 Like

@balaraj.pubalan

Sequence:
Assign activity: yesterday = Now.AddDays(-1)

Get Outlook Mail Messages activity:
Account: “Your Outlook Account”
MailFolder: “Inbox”
Filter: “[ReceivedTime] >= '” + yesterday.ToString(“MM/dd/yyyy”) + “’ AND [ReceivedTime] < '” + Now.ToString(“MM/dd/yyyy”) + “'”

For Each activity (TypeArgument: MailMessage):
// Process each email here, for example, you can log the email subject and received time
Log Message: "Email Subject: " + item.Subject + ", Received Time: " + item.Headers(“Date”)

Hi @balaraj.pubalan

Try the below simple C# to filter with the yesterday received mails.

"[ReceivedTime] >= '" + DateTime.Now.AddDays(-1).ToString("MM/dd/yyyy")

Hope it helps!!

1 Like

Thank you @balaraj.pubalan

If you find the solution do mark it as solution to close the loop.

Happy Automation!!

Thanks guys…it works :slight_smile:

1 Like

Hi @balaraj.pubalan

Try this:
“[ReceivedTime] >= '” + DateTime.Now.AddDays(-1).ToString(“MM/dd/yyyy 00:00 AM”) + “’ AND [ReceivedTime] <= '” + DateTime.Now.AddDays(-1).ToString(“MM/dd/yyyy 11:59 PM”) + “'”

1 Like

May i know why i get this error?
Get Outlook Mail Messages: Cannot parse condition. Error at “'07/20/2023 14:06"”.

@balaraj.pubalan

use this format in place of that:
“07/20/2023 14:06:00”

1 Like

Added as below and its works as per my expectation:
“[ReceivedTime] < '” + DateTime.Now.AddDays(-1).ToString(“MM/dd/yyyy hh:mm”) + “'”
Thanks. :slight_smile:

1 Like

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