import imaplib
box = imaplib.IMAP4_SSL('imap.mail.microsoftonline.com', 993)
box.login("user@domain.com", "password")
box.select('Inbox')
# 如果是查找收件箱所有邮件则是box.search(None, 'ALL')
typ, data = box.search(None, 'from', 'mailer-daemon@googlemail.com')
# 以防万一先查看邮件内容,确认是要删除的邮件
for num in data[0].split():
typ, data = box.fetch(num, '(RFC822)')
print('Message %s\n%s\n' % (num, data[0][1]))
box.close()
box.logout()
import imaplib
box = imaplib.IMAP4_SSL('imap.mail.microsoftonline.com', 993)
box.login("user@domain.com", "password")
box.select('Inbox')
# 如果是查找收件箱所有邮件则是box.search(None, 'ALL')
typ, data = box.search(None, 'from', 'mailer-daemon@googlemail.com')
for num in data[0].split():
box.store(num, '+FLAGS', '\\Deleted')
box.expunge()
box.close()
box.logout()