python poplib get attachment -
i trying access pop3 email server. polling messages , downloading attachments each 1 of them. can login , messages cannot figure out how attachment, need parse later. i'm thinking save tmp dir until process it.
here's got far:
pop = poplib.pop3_ssl(server) pop.user(usr) pop.pass_(pwd) f = open(file_dir, 'w') num_msgs = len(pop.list()[1]) msg_list in range(num_msgs): msg in pop.retr(msg_list+1)[1]: mail = email.message_from_string(msg) part in mail.walk(): f.write(part.get_payload(decode=true)) f.close()
this code pieced examples found online no solid example of getting attachment. file i'm writing empty. missing here? in advance.
i know old question, in case: value you're passing email.message_from_string list of contents of email, each element line. need join string representation of email:
mail = email.message_from_string("".join(msg))
Comments
Post a Comment