Set Multiple Filters in Get outlook mail message

I need to set two conditions in “filter” in Get outlook mail message. One of them is sender’s email address and the other one is the message received in the last hour. I have already built two conditions and they can work separately. But if i tried to combine these two, it failed.

First condition(used for mapping to get email addresses in excel):
String.Join(" OR ", dtMappingAddress.AsEnumerable().[Select](Function(row) “[SenderEmailAddress]=” + “'” + row(“Email address”).ToString() + “'”).ToArray())

Second condition:
“[ReceivedTime] >= '” + DateTime.Now.AddHours(-1).ToString(“MM/dd/yyyy HH:mm tt”) + “'”

I tried the suggestions from Chatgpt but they couldn’t work as well. Thanks in advance.

@abc0106
Dim filterCondition As String = “(” + String.Join(" OR ", dtMappingAddress.AsEnumerable().[Select](Function(row) “[SenderEmailAddress] = '” + row(“Email address”).ToString() + “'”).ToArray()) + “) AND [ReceivedTime] >= '” + DateTime.Now.AddHours(-1).ToString(“MM/dd/yyyy HH:mm tt”) + “'”

  • In StudioX: Double-click the Get Outlook Mail Messages activity, click the “Options” button next to the “Filter” field, paste the filterCondition string into the text box, and click “OK.”
  • In Studio: Set the Filter property of the activity to the filterCondition string.

Hi @abc0106

Can you try this

String.Join(" OR ", dtMappingAddress.AsEnumerable().Select(Function(row) "[SenderEmailAddress] = '" + row("Email address").ToString + "'").ToArray) + " AND " + "[ReceivedTime] >= '" + DateTime.Now.AddHours(-1).ToString("MM/dd/yyyy HH:mm tt") + "'"

Regards,

Hi @abc0106

"([ReceivedTime] >= '" + DateTime.Now.AddHours(-1).ToString("MM/dd/yyyy HH:mm tt") + "') AND (" + String.Join(" OR ", dtMappingAddress.AsEnumerable().Select(Function(row) "[SenderEmailAddress]='" + row("Email address").ToString() + "'").ToArray()) + ")"

Hi @abc0106

Try the below one for filtering in Get outlook mail message activity,

MailMessage.From.Address = "example@example.com" AndAlso MailMessage.ReceivedTime > DateTime.Now.AddHours(-1)

Hope it helps!!

It works! Thanks a lot.

1 Like

@abc0106
Your Welcome.
Happy Automation.

Thanks for your suggestion. You are always kind.

1 Like

Thanks for your time. I believe it can work as well. I found a solution.

1 Like

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