Stef_99
(Mary)
August 25, 2025, 5:47am
1
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
farook3
(Farook)
August 25, 2025, 5:54am
2
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
Stef_99
(Mary)
August 25, 2025, 6:09am
5
@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:.
Stef_99
(Mary)
August 25, 2025, 6:41am
7
@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%'"
Stef_99
(Mary)
August 25, 2025, 6:51am
9
@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%'"
Stef_99
(Mary)
August 25, 2025, 7:11am
12
@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)
Stef_99
(Mary)
August 25, 2025, 7:26am
15
@Mir.Jasimuddin my code as below.
Please share the error details
Stef_99
(Mary)
August 25, 2025, 7:43am
17
@Mir.Jasimuddin
Get Outlook Mail Message : Condition is not valid
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") & "'"
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
Stef_99
(Mary)
August 25, 2025, 8:14am
20
@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