我正在尝试通过 UID 删除电子邮件。这是我正在访问的 hotmail 电子邮件帐户。
这就是我正在做的:
imap = imaplib.IMAP4_SSL('imap-mail.outlook.com')
imap.login('[email protected]', "password")
resp, _ = imap.select('Inbox')
mbox_response, msgnums = imap.search( None,'FROM', '[email protected]')
messages = [] #Appending UID to this dictionary
for num in msgnums[0].split():
msg_uid = imap.fetch(num, 'UID')
messages.append({'uid':imap.fetch(num, 'UID')})
print(messages)
我得到以下输出:
[{
'uid': ('OK', [b'1 (UID 111)']),
'uid': ('OK', [b'2 (UID 114)'])
}]
如何使用这些 UID 来删除特定消息?
我已经尝试过但没有成功...
for m in messages:
imap.store(m['uid'],'+X-GM-LABELS', '\\Trash')
我收到以下错误:
TypeError: can't concat tuple to bytes
from imap_tools import MailBox, A
with MailBox('imap.mail.com').login('[email protected]', 'pwd', 'INBOX/test') as mailbox:
# DELETE all flagged messages from current folder (INBOX/test)
mailbox.delete(mailbox.uids(A(flagged=True)))
https://github.com/ikvk/imap_tools
阅读 lib 文档了解详细信息