Download a specific email from Gmail using Python

前端 未结 3 1650
不知归路
不知归路 2021-02-07 11:13

Can someone help me customize an existing code sample?

I can see from the following article how to connect to gmail and download content, but I can\'t figure out how to

3条回答
  •  滥情空心
    2021-02-07 12:10

    import imaplib
    from datetime import datetime, timedelta
    
    obj = imaplib.IMAP4_SSL('imap.gmail.com',993)
    obj.login('username','password')
    obj.select()
    
    today = datetime.today()
    cutoff = today - timedelta(days=5)
    dt = cutoff.strftime('%d-%b-%Y')
    typ, data = obj.search(None, '(SINCE %s) (FROM "Alerts@foobank.com")'%(dt,))
    print data
    

提交回复
热议问题