Python Forum
Download email attachments and then format the data
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Download email attachments and then format the data
#1
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[]'])
Reply
#2
I was able to figure this out.

Use:

print(message.get_payload(1))
to get the second object which is the text file attachment.
Reply
#3
Thank you for notifying and posting the solution to your issue.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020