Get Outlook message from date to today date

Dear Team,

Filter1 - From Specific Mail id only
Filter2 - I have two datetime variables StartDate and End Date, i woul like to get the mails for only between these two dates.
Please let me know, how to apply above filters in Get Outlook Messages Activity.

Thanks & Regards,
Amol Golhar

Hi,

How about the following?

"[SenderEmailAddress] = 'test@example.com' AND [Received] >= '" + StartDate.ToString("d") + " 00:00AM' AND [Received] < '"+ EndDate.AddDays(1).ToString("d") + " 00:00AM'" 

Regards,

To filter emails by sender and date range in UiPath using the “Get Outlook Mail Messages” activity, you can apply filters using the properties panel. Here’s how to set it up:

  1. Drag the “Get Outlook Mail Messages” Activity: Add this activity to your sequence.
  2. Configure the Properties: In the properties panel of the activity:
  • MailFolder: Set this to “Inbox” or the specific folder you want to search in.
  • Top: Define the maximum number of messages you want to retrieve.
  • Account: If necessary, specify the Outlook account to use.
  1. Apply Filter for Sender and Date Range: In the “Filter” property, you’ll need to use a DASL query string to filter emails by the sender’s email address and the date range. Construct your query as follows:

“@SQL=” & Chr(34) & “urn:schemas:httpmail:fromemail” & Chr(34) & " LIKE ‘%sender@example.com%’ AND " & _
Chr(34) & “urn:schemas:httpmail:datereceived” & Chr(34) & " >= ‘" & _
StartDate.ToString(“g”) & "’ AND " & _
Chr(34) & “urn:schemas:httpmail:datereceived” & Chr(34) & " <= ‘" & _
EndDate.ToString(“g”) & "’"

Replace sender@example.com with the specific email address you’re filtering for. The StartDate and EndDate should be your DateTime variables formatted to a string that Outlook understands (usually “g” for general date format works).

  1. Assign Filter to the Activity: Assign the above DASL query string to the “Filter” property of the “Get Outlook Mail Messages” activity.
  2. Output the Results: Store the results in a variable, typically of type List<MailMessage>, to hold the emails that match your criteria.

Hi @Amol_Golhar

Try the below syntax:

"[From] = 'specific_email@example.com' AND [ReceivedTime] >= '" + StartDate.ToString("MM/dd/yyyy HH:mm:ss") + "' AND [ReceivedTime] <= '" + EndDate.ToString("MM/dd/yyyy HH:mm:ss") + "'"

Hope it helps

@Amol_Golhar

"[From] = 'specific_email@example.com' AND [ReceivedTime] >= '" + StartDate.ToString("yyyy-MM-dd HH:mm:ss") + "' AND [ReceivedTime] <= '" + EndDate.ToString("yyyy-MM-dd HH:mm:ss") + "'"

Hi @Amol_Golhar

Check the below filter expression which filters sender mail address and Mails received between date to today date,

Let’s say output variable of the Get Outlook mail message is List_MailMessages.

- Assign -> startDate [DateTime datatype] = Provide the date from where you want to get

- Assign -> endDate [DateTime datatype] = DateTime.Now

- Assign ->  List_MailMessages =  List_MailMessages.Where(Function(mail) mail.SenderEmailAddress = "example@example.com" AndAlso mail.ReceivedTime >= startDate AndAlso mail.ReceivedTime <= endDate).ToList()

List_MailMessages variable store the filtered mails.

Hope it helps!!

Hi @Amol_Golhar

Try below expression in Get Outlook Mail Message - Filter

"[From] = 'sender@example.com' AND [ReceivedTime] >= '" + StartDate.ToString("yyyy-MM-dd HH:mm:ss") + "' AND [ReceivedTime] <= '" + EndDate.ToString("yyyy-MM-dd HH:mm:ss") + "'"

Note: StartDate and EndDate will be in DateTime Variable.

Hope it will helps you :slight_smile:
Cheers!!

Dear Team,

When i am using any filter, no messages coming.
Without filter it is coming.

attaching the project, please check.
Main.xaml (7.8 KB)
project.json (1.7 KB)

Thanks & Regards,
Amol Golhar

Dear,
Could you please check i have replied another query.

Thanks & Regards,
Amol Golhar

HI,

How about using SenderEmailAddress instead of From in the filter string?

Regards,

By SenderEmailAddress also not working.

Thanks & Regards,
Amol Golhar

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