Get only NEW Emails imaplib and python

前端 未结 5 1653
伪装坚强ぢ
伪装坚强ぢ 2020-12-04 14:49

This is a smaller portion of a bigger project. I need to only get unread emails and a parse their headers. How can I modify the following script to only get unread emails?

5条回答
  •  一整个雨季
    2020-12-04 15:20

    You may use imap_tools package: https://pypi.org/project/imap-tools/

    from imap_tools import MailBox, AND
    with MailBox('imap.mail.com').login('test@mail.com', 'password', 'INBOX') as mailbox:
        # get unseen emails from INBOX folder
        for msg in mailbox.fetch(AND(seen=False)):
            print(msg.headers)
    

提交回复
热议问题