How to filter an outlook email address using an array

How can I use the outlook filter option to exclude multiple emails?
I am using “ExcludeMail” as array

“[senderemailaddress] <> '”+in_ExcludeMail+"’"

@Julian_Claessen Can you use this in an Assign Statement and check if it Works :

msgs = msgs.Where(Function(x)ExcludeMail.Any(Function(y)x.Sender.ToString.Contains(y.ToString))).ToList

Where ExcludeMail is an Array of String that contains mail addresses, and msgs is the Output Of Get Mail Messages Activity i.e List (Of MailMessage)

Should I mention it after the for each loop or before? I keep getting a error

@Julian_Claessen I think you need to use InboxMails variable instead of msgs variable :sweat_smile: . The Order is right but make sure you use exclude variable in the expression that i have given instead of ExcludeMail

1 Like

It works but it only selects the mails mentioned in the exclude array, which need to be the opposite way around :thinking:

Eg:
Exclude: {“abc@gmail.com”, “def@gmail.com”}
InboxMail: {“aaa@gmail.com”, “abc@gmail.com”, “bbb@gmail.com”, “def@gmail.com”}

Results should be mails only from : aaa@gmail.com and bbb@gmail.com

1 Like

@Julian_Claessen Oh Yes. I forgot you need to exclude the mails :sweat_smile: There is a NOT operator missing, try below expression :

InboxMails = InboxMails.Where(Function(x)Not(exclude.Any(Function(y)x.Sender.ToString.Contains(y.ToString)))).ToList

2 Likes

It works! Thanks :grinning: :ok_hand:

1 Like

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