Download a csv file from gmail using python

后端 未结 4 1210
無奈伤痛
無奈伤痛 2020-12-17 06:40

I tried different python scripts for download a CSV attachment from Gmail. But I could not able to get it.Is this possible. If it is possible which python script should I us

4条回答
  •  不知归路
    2020-12-17 07:24

    from imap_tools import MailBox
    
    # get all .csv attachments from INBOX and save them to files
    with MailBox('imap.my.ru').login('acc', 'pwd', 'INBOX') as mailbox:
        for msg in mailbox.fetch():
            for att in msg.attachments:
                if att.filename.lower().endswith('.csv'):
                    with open('C:/1/{}'.format(att.filename), 'wb') as f:
                        f.write(att.payload)
    

    https://github.com/ikvk/imap_tools

提交回复
热议问题