BNK
(nirmal)
September 28, 2021, 9:00am
1
How to read a mail between particular dates and time ?
I need to read the mails of particular week with time. User will give from date(09/15/2021 14:28:00) and to date(09/23/2021 18:00:00). Can we do this in UiPath?
For reading mail i used IMAP Activity.
Hi
Hope the below steps helps you resolve this
—get IMAP mail activity and get the output as a list of mailmessage named out_mailmessage
—then use a FOR EACH activity and pass the above variable as input
Change the type argument as System.Net.Mail.MailMessage
—inside the loop use a IF condition like this
Datetime.ParseExact(item.Headers(“Date”).SubString(0,10), “MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture) >= Datetime.ParseExact((“09/15/2021 14:28:00”).ToString.SubString(0,10),”MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
AND
Datetime.ParseExact(item.Headers(“Date”).SubString(0,10), “MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture) <= Datetime.ParseExact((“09/23/2021 18:00:00”).ToString.SubString(0,10),”MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
Cheers @BNK
BNK
(nirmal)
September 28, 2021, 2:38pm
3
Hi palaniyappan
I got above error in if condition. please help me to solve this.
Gokul001
(Gokul Balaji)
September 28, 2021, 2:42pm
4
Hi @BNK
You can try to use the expression in the filter properties:
" [ReceivedTime] >= ‘09/15/2021 14:28:00’ AND [ReceivedTime] <= ‘09/23/2021 18:00:00’ "
Check the below thread
Hi @BNK
Check this documentation. We have a few example filter expressions.
This Expression for Get Outlook mail
Regards
Gokul
Hope it will work
Regards
Gokul
BNK
(nirmal)
September 28, 2021, 2:46pm
5
Hi @Gokul001
That command will work only for Outlook Activities. Here i am using Imap activities
Gokul001
(Gokul Balaji)
September 28, 2021, 3:01pm
6
Hi @BNK
Check with the below expression
" [ReceivedTime] >= ‘09/15/2021 14:28:00’ AND [ReceivedTime] <= ‘09/23/2021 18:00:00’ "
Regards
Gokul
Palaniyappan:
Datetime.ParseExact(item.Headers(“Date”).SubString(0,10), “MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture) >= Datetime.ParseExact((“09/15/2021 14:28:00”).ToString.SubString(0,10),”MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
AND
Datetime.ParseExact(item.Headers(“Date”).SubString(0,10), “MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture) <= Datetime.ParseExact((“09/23/2021 18:00:00”).ToString.SubString(0,10),”MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
I have updated the query
Check once
@BNK
BNK
(nirmal)
September 29, 2021, 3:57am
9
If I used above expression I got below error.
BNK
(nirmal)
September 29, 2021, 4:18am
10
Hi @Palaniyappan
I Used above mentioned code but i got below error
nougain
(Ramesh Nougain)
September 29, 2021, 5:38am
11
@BNK Earlier proposed solutions are client-side solutions (post retrieving the emails) and should work, albeit maybe only partially depending on the “Top” property value covering all the emails fulfilling your datetime criteria . However, if you want to retrieve with a filter at the email server end using the IMAP , then try the FilterExpression like:
“(BEFORE 22-Sep-2021) (SINCE 15-Sep-2021)”
Generate the above expression dynamically, such as
“(BEFORE " +Today.AddDays(-7).ToString(“dd-MMM-yyyy”) +”) (SINCE " +Today.AddDays(-14).ToString(“dd-MMM-yyyy”) +“)”
Please note, BEFORE and SINCE disregard time and timezone. If you want time & zone, then explore further here .
Explore… Get IMAP Mail Messages (uipath.com)
Full Details… rfc3501 (ietf.org)
prasath17
(Guru)
September 29, 2021, 6:42pm
12
@BNK - Haven’t tried the solution which I shared??
BNK
(nirmal)
September 30, 2021, 4:13am
13
Hi @prasath17
I need a expression with time. But in imap properties i am not find a expression with date and time.
prasath17
(Guru)
September 30, 2021, 9:34am
14
@BNK - please check my post again i have provided the solution with time only. This method is different where you don’t have to deal with filter.
Fine
Try with this expression
CDate(item.Headers(“Date”)) >= Datetime.ParseExact((“09/15/2021 14:28:00”).ToString.SubString(0,10),”MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
AND
CDate(item.Headers(“Date”)) <= Datetime.ParseExact((“09/23/2021 18:00:00”).ToString.SubString(0,10),”MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
@BNK
system
(system)
Closed
October 3, 2021, 9:51am
16
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.