python extract email attachment

Solutions on MaxInterview for python extract email attachment by the best coders in the world

showing results for - "python extract email attachment"
Carlos
02 Jan 2020
1from imap_tools import MailBox
2
3# get all attachments from INBOX and save them to files
4with MailBox('imap.my.ru').login('acc', 'pwd', 'INBOX') as mailbox:
5    for msg in mailbox.fetch():
6        for att in msg.attachments:
7            print(att.filename, att.content_type)
8            with open('C:/1/{}'.format(att.filename), 'wb') as f:
9                f.write(att.payload)
10