Fetch an email with imaplib but do not mark it as SEEN

前端 未结 4 581
慢半拍i
慢半拍i 2020-11-28 09:59

I want to parse some emails from a user \'s inbox but when I do:

typ, msg_data = imap_conn.fetch(uid, \'(RFC822)\')

It marks the email as S

4条回答
  •  遥遥无期
    2020-11-28 10:25

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

    from imap_tools import MailBox, Q
    
    # get list of email subjects from INBOX folder
    with MailBox('imap.mail.com').login('test@mail.com', 'password') as mailbox:
        # mark_seen=False - not mark emails as seen on fetch
        subjects = [msg.subject for msg in mailbox.fetch(mark_seen=False)]
    

提交回复
热议问题