Filter subject and receive date

Hello,
I have filter receiveDate email outlook as below.

“[ReceivedTime] >= '” + DateTime.Today.ToString("yyyy-MM-dd 09:00 ) + “’ AND [ReceivedTime] < '” + DateTime.Today.AddDays(-1).ToString(“yyyy-MM-dd 08:00”) + “'”

I want to add filter subject.
How to edit my code?

Thankyou

Hi @Stef_99
“[ReceivedTime] >= '” + DateTime.Today.AddHours(9).ToString(“MM/dd/yyyy hh:mm tt”) +
“’ AND [ReceivedTime] < '” + DateTime.Today.AddDays(1).AddHours(8).ToString(“MM/dd/yyyy hh:mm tt”) +
“’ AND [Subject] = ‘Invoice’”
This is the correct way try this and let me know if it is working

Hey @Stef_99,

Use AND with [Subject]. Example:
"[ReceivedTime] >= '" + DateTime.Today.ToString("yyyy-MM-dd 09:00") + "' AND [ReceivedTime] < '" + DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd 08:00") + "' AND [Subject] = 'YourSubject'"

Thanks

@Stef_99,
Please follow the UiPath docs for “Get Outlook Mail Message”, where you can find multiple options for using filter.

Use below Query, to filter to mails by Subject
“[ReceivedTime] >= '” + DateTime.Today.ToString("yyyy-MM-dd 09:00 ) + “’ AND [ReceivedTime] < ‘” + DateTime.Today.AddDays(-1).ToString(“yyyy-MM-dd 08:00”) + “’”
+“AND [Subject] = ‘Product Roadmap’”

Activities - Get Outlook Mail Messages

@Mir.Jasimuddin If sometimes subject have text FW: in front of subject.
If I want to use contains with text.

Can you suggest me?

Hey @Stef_99,

Use LIKE with wildcard. Example:
"[Subject] LIKE '%YourText%'" will capture subjects containing YourText, even if prefixed with FW:.

@Mir.Jasimuddin error Condition is not valid

@Stef_99,

In UiPath you can not use multiline try to use in one line or break into more assign.

Try this:

"[ReceivedTime] >= '" & DateTime.Today.ToString("yyyy-MM-dd 09:00") & "' AND [ReceivedTime] < '" & DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd 08:00") & "' AND [Subject] LIKE '%YourText%'"

@Mir.Jasimuddin I use in 1 line but same error.

@Stef_99

Please try with below filter
All mail messages with the subject contains “Post”

“@SQL=”“urn:schemas:httpmail:subject”" like ‘%Post%’"

All the filter options are available on “GetOutlookMailMessage” document

Share the screenshot,

Try this:

"[ReceivedTime] >= '" & DateTime.Today.ToString("yyyy-MM-dd 09:00") & "' AND [ReceivedTime] < '" & DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd 08:00") & "' AND [Subject] LIKE '%YourText%'"

@Mir.Jasimuddin I remove filter ReceiveDate and try filter subject only.
But error same.

“[Subject] LIKE ‘%Post%’”

Mary,
Try with below filter. I have just tried; it is working fine for me.

“@SQL=”“urn:schemas:httpmail:subject”" like ‘%Post%’"
GetMailMessage.xaml (7.2 KB)

Please share screenshots

@Mir.Jasimuddin my code as below.

Please share the error details

@Mir.Jasimuddin

Get Outlook Mail Message : Condition is not valid

  1. Assign (Filter for date):
mailFilter = "[ReceivedTime] >= '" & DateTime.Today.ToString("MM/dd/yyyy 09:00") & "' AND [ReceivedTime] < '" & DateTime.Today.AddDays(-1).ToString("MM/dd/yyyy 08:00") & "'"
  1. Assign (Filter subject from results):
filteredMails = mails.Where(Function(m) m.Subject IsNot Nothing AndAlso m.Subject.Contains("YourText")).ToList()

Try this alternative and adjust according to you variables

@Mir.Jasimuddin What type variable filteredMails and mailFilter ?

@Stef_99,

Use this Filter - "[Received] >= '" + DateTime.Today.AddDays(0).ToString("d") + " 00:00AM' AND [Received] < '"+ DateTime.Today.AddDays(1).ToString("d") + " 00:00AM' AND [Subject] = '"+strSubject+"'"

strSubject is a string variable which you can use to store dynamic email subject.

Just change your email account and try from this sample code. It’s working fine for me

OutlookFiltering.zip (112.5 KB)

Output:

++Remember to change the date range as per your requirement. I had used as per my emails availability in my mailbox

1 Like