Getting n most recent emails using IMAP and Python

前端 未结 5 1022
终归单人心
终归单人心 2020-12-28 20:56

I\'m looking to return the n (most likely 10) most recent emails from an email accounts inbox using IMAP.

So far I\'ve cobbled together:

import imapl         


        
5条回答
  •  爱一瞬间的悲伤
    2020-12-28 21:19

    # get recent one email
    from imap_tools import MailBox
    with MailBox('imap.mail.com').login('test@mail.com', 'password', 'INBOX') as mailbox:
       for message in mailbox.fetch(limit=1, reverse=True):
           print(msg.date_str, msg.subject)
    

    https://github.com/ikvk/imap_tools

提交回复
热议问题