Download email attachments and then format the data - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Networking (https://python-forum.io/forum-12.html) +--- Thread: Download email attachments and then format the data (/thread-13256.html) |
Download email attachments and then format the data - SpencerH - Oct-06-2018 I have been working on a script for work that downloads email via IMAP, so I use IMAPClient to do that and I can get the emails and see the content. Now I am trying to figure out how to get the attachment and format the data. The attachment is a Tab delimited file that is in txt format. Here is as far as I get before getting stuck: import pyzmail from imapclient import IMAPClient server = IMAPClient('mail.server.com', use_uid=True, ssl=False) server.login('[email protected]', 'VerCrazyPassWord') select_info = server.select_folder('Inbox') server.search(['SINCE', '01-Oct-2018']) rawMessage = server.fetch([157], ['BODY[]', 'FLAGS']) print(rawMessage) message = pyzmail.PyzMessage.factory(rawMessage[157][b'BODY[]']) RE: Download email attachments and then format the data - SpencerH - Oct-06-2018 I was able to figure this out. Use: print(message.get_payload(1))to get the second object which is the text file attachment. RE: Download email attachments and then format the data - j.crater - Oct-06-2018 Thank you for notifying and posting the solution to your issue. |