【发布时间】:2020-12-18 00:15:08
【问题描述】:
我下面的 Python 代码运行但不会删除我希望从我的测试 gamil\inbox 中删除的选定电子邮件。我不确定我在这里做错了什么。我将非常感谢任何帮助。
import imaplib
import datetime
m = imaplib.IMAP4_SSL("imap.gmail.com") # server to connect to
print("{0} Connecting to mailbox via IMAP...".format(datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S")))
m.login('bb_xxxxx@gmail.com', 'gmail_pass')
print("{0} Searching Inbox by sender...".format(datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S")))
m.select('Inbox') #select folder to search
status, messages = m.search(None, 'FROM "location-history-noreply@google.com"') # search for specific mails by sender
print("{0} Flagging selected mail as deleted...".format(datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S")))
for mail in messages[0].split():
m.store(mail, "+FLAGS", "\\Deleted")
m.expunge()
print("{0} Done. Closing connection & logging out.".format(datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S")))
m.close()
m.logout()
【问题讨论】: