imap - how to delete messages

后端 未结 9 666
孤独总比滥情好
孤独总比滥情好 2020-12-14 08:00

How can I delete messages from the mail box? I am using this code, but the letters are not removed. Sorry for my English.

def getimap(self,server,port,login,         


        
9条回答
  •  天命终不由人
    2020-12-14 08:51

    This is the working code for deleting all emails in your inbox:

    import imaplib
    box = imaplib.IMAP4_SSL('imap.mail.microsoftonline.com', 993)
    box.login("user@domain.com","paswword")
    box.select('Inbox')
    typ, data = box.search(None, 'ALL')
    for num in data[0].split():
       box.store(num, '+FLAGS', '\\Deleted')
    box.expunge()
    box.close()
    box.logout()
    

提交回复
热议问题