I am trying to access POP3 email server. I will be polling messages and downloading attachments for each one of them. I can successfully login and get the messages but cannot figure out how to actually get the attachment, which I would need to parse later. I'm thinking I could save to tmp dir until I process it.
Here's what I got so far:
pop = poplib.POP3_SSL(server)
pop.user(usr)
pop.pass_(pwd)
f = open(file_dir, 'w')
num_msgs = len(pop.list()[1])
for msg_list in range(num_msgs):
for msg in pop.retr(msg_list+1)[1]:
mail = email.message_from_string(msg)
for part in mail.walk():
f.write(part.get_payload(decode=True))
f.close()
This is code I pieced together from the examples I found online but no solid example of actually getting the attachment. The file I'm writing to is empty. What am I missing here?