'Searching for multiple FROM addresses using imapclient.IMAPClient.search in python
I have been searching but it looks as if the syntax has changed since the posts I have found have been posted. I am trying to find emails from multiple addresses. This works:
UIDs = conn.search([
['FROM','[email protected]'],
[u'SINCE', datetime.date(2022, 3, 6)],
])
I was hoping for something like this:
UIDs = conn.search([
'OR'[
['FROM','[email protected]'],['FROM','[email protected]']
],
[u'SINCE', datetime.date(2022, 3, 6)],
])
But I can't seem to find any variation of OR that works. I have tried an example from Automate the boring stuff, and he recommends this:
imapObj.search(['OR FROM [email protected] FROM [email protected]']
This doesn't work for me either. I've checked imapclient page and don't find the answer there either: https://imapclient.readthedocs.io/en/master/index.html
Any guidance would be appreciated!
Solution 1:[1]
I am not familiar with the imapclient library, but I see that the API allows sending raw strings, so if it's not sending exactly what you want, you can override it.
This should do it for you, making it as unambiguous as possible:
conn.search('OR (FROM "[email protected]") (FROM "[email protected]")')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Max |
