How to read a mail between particular dates and time?

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

Hi palaniyappan
I got above error in if condition. please help me to solve this.

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

Hope it will work

Regards
Gokul

Hi @Gokul001
That command will work only for Outlook Activities. Here i am using Imap activities

Hi @BNK

Check with the below expression
" [ReceivedTime] >= ‘09/15/2021 14:28:00’ AND [ReceivedTime] <= ‘09/23/2021 18:00:00’ "

Regards
Gokul

I have updated the query
Check once
@BNK

@BNK - Here you go…

  1. Get IMAP Messages…I am saving my output as “Emails” . I have given top 100. Please increase this limit as per your requirement.

image

  1. Assign Activity…

    Emails.AsEnumerable().Where(Function(x) cdate(x.Headers("Date")) >= cdate("09/15/2021 14:28:00") and cdate(x.Headers("Date")) <= cdate("09/23/2021 18:00:00") ).tolist
    
  2. Write Line

    "Total No.of emails received during the given time: " +Emails.Count.ToString
    
  3. Write Line → I have tried to print the dates for the emails using this code…just for verification purposes…

     string.join(vbcr,Emails.AsEnumerable().Select(function(x) x.Headers("Date").ToString))
    

Hope this helps…

If I used above expression I got below error.
image

Hi @Palaniyappan

 I Used above mentioned code but i got below error

image

@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)

@BNK - Haven’t tried the solution which I shared??

Hi @prasath17
I need a expression with time. But in imap properties i am not find a expression with date and time.

@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

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