Applying filter to read emails from multiple SenderEmailAddress in win32com

1.2k views Asked by At

I am trying to read emails received from specific email addresses (more than 1). For single use case, the following code seems to be working -

import win32com.client

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)

messages = inbox.Items.Restrict("[SenderEmailAddress] = '[email protected]' ")

For providing multiple email ID as a filter I tried the following two approaches but that does not work -

messages = inbox.Items.Restrict("[SenderEmailAddress] = '[email protected]; [email protected]' ")
messages = inbox.Items.Restrict("[SenderEmailAddress] In ['[email protected]', '[email protected]'] ")

How can I provide multiple filter values like in this scenario?

1

There are 1 answers

1
Dmitry Streblechenko On BEST ANSWER

You need to include multiple conditions using the OR operator:

" ([SenderEmailAddress] = '[email protected]' ) or ([SenderEmailAddress] = '[email protected]') "