0

Python imaplib Yahoo error

Want to search folder "SPAM", for specific_user@any domain, and delete found mail. Code below ... import imaplib box = imaplib.IMAP4_SSL('imap.mail.yahoo.com', 993) box.login("xxxxxxxx@yahoo.com","xxxxxxxxxx") box.select('SPAM') typ, data = box.search(None, 'from','name@*.*') for num in data[0].split(): box.store(num, '+FLAGS', '\\Deleted') box.expunge() box.close() box.logout() ... is generating these errors below, please assist in debugging. Thanks. Traceback (most recent call last): File "C:\Users\Desktop\Desktop\Python Spam Buster\test.py", line 6, in <module> typ, data = box.search(None, 'from','name@*.*') File "C:\Users\Desktop\AppData\Local\Programs\Python\Python310\lib\imaplib.py", line 734, in search typ, dat = self._simple_command(name, *criteria) File "C:\Users\Desktop\AppData\Local\Programs\Python\Python310\lib\imaplib.py", line 1230, in _simple_command return self._command_complete(name, self._command(name, *args)) File "C:\Users\Desktop\AppData\Local\Programs\Python\Python310\lib\imaplib.py", line 968, in _command raise self.error("command %s illegal in state %s, " imaplib.IMAP4.error: command SEARCH illegal in state AUTH, only allowed in states SELECTED

19th Aug 2022, 10:09 PM
Linh Lee
1 Antwort
+ 1
Hey there! So to fix that problem you mentioned, try adding the line box.select('SPAM') right after box.login(). This will select the mailbox ya wanna mess with and change the state of the connection to "SELECTED", so you can use the search() command without any problems. If ya need any more help or have any other questions, just give me a shout and I'll try to help ya out as best as I can.
26th Mar 2023, 1:20 PM
Deku
Deku - avatar