问题描述
好的,所以我今天决定从我的旧电子邮件帐户中删除所有旧电子邮件。现在我有大约 40,000 多封电子邮件需要删除,所以我采用了显而易见的方法并编写了一个脚本来为我执行此操作。
一切正常运行了大约 10 分钟,直到我遇到了 IMAP 出现 Loggout 错误的问题。代码运行良好,我只需要知道是否有办法禁用或绕过它,以便我可以运行此脚本,直到我的所有电子邮件都被删除。
这是脚本(由于明显的原因更改了用户名和密码):
import imaplib
import email
from tqdm import tqdm
from email.header import decode_header
# Account credentials
username = "username@domain.com"
password = "password"
imap = imaplib.IMAP4_SSL("imap.mail.yahoo.com")
imap.login(username,password)
imap.select("Archive")
status,messages = imap.search(None,"ALL")
messages = messages[0].split(b' ')
amtOfMessages = len(messages)
print("Clearing all emails in the ARCHIVE folder")
print("Total emails in folder: ",amtOfMessages)
#tqdm is a library I'm using to display a progress bar in the cmd line
for i in tqdm(range(amtOfMessages)):
_,msg = imap.fetch(messages[i],"(RFC822)")
imap.store(messages[i],"+FLAGS","\\Deleted")
imap.expunge()
imap.close()
imap.logout()
print("ALL MESSAGES DELETED FROM ARCHIVE FOLDER")
print("Logged out of account...")
最后,这是我得到的错误的回溯
Traceback (most recent call last):
File "/Documents/EmailScripts/quickstart.py",line 27,in <module>
_,"(RFC822)")
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/imaplib.py",line 548,in fetch
typ,dat = self._simple_command(name,message_set,message_parts)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/imaplib.py",line 1230,in _simple_command
return self._command_complete(name,self._command(name,*args))
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/imaplib.py",line 1049,in _command_complete
raise self.abort('command: %s => %s' % (name,val))
imaplib.abort: command: FETCH => IMAP4rev1 Server logging out
编辑:说“超时”时口误。意思是说退出。已进行更改。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)