Problem deleting emails in gmail using imaplib

后端 未结 4 543
渐次进展
渐次进展 2021-01-05 16:23

I try to remove message from inbox folder and all alright, but when i switched to All Mail folder the removing does not work. expunge() method returns (\'

4条回答
  •  悲哀的现实
    2021-01-05 16:47

    it moves all the mail in a given gmail label to the gmail Trash

    #!usr/bin/python
    import email, imaplib
    
    user = 'xxx'
    pwd = 'xxx'
    
    m = imaplib.IMAP4_SSL("imap.gmail.com")
    m.login(user,pwd)
    
    m.select("some_gmail_label")
    m.store("1:*",'+X-GM-LABELS', '\\Trash')
    
    m.expunge() # should be useless, but gmail server says it is ok
    

    Remember to refresh your gmail interface cause it has cache

提交回复
热议问题