Using write function within email Module to write get_payload to afile.

C

Chuck Amadi

fp = file("/home/chuck/pythonScript/testbox")

mbox = mailbox.UnixMailbox(fp, email.message_from_file)
# list of body messages.
bodies = []

# mail is the file object
for mail in mbox:
print mail['Subject']
print mail.get_content_type()#text/plain
print mail.get_payload()



fp = file("/home/chuck/pythonScript/testbox")
mb = mailbox.UnixMailbox(fp, email.message_from_file)

mailout = file("/home/chuck/pythonScript/SurveyResults.txt","w")
#for mail in fp.readlines():
# mailout.write(mail)

## Something like this I have tried a few things cant get my head
## round it

for bodymsg in fp:
bodymsg= mail.get_payload()
bodies.append(bodymsg)
mailout.write(bodymsg)

print "testbox mailbox file copied...to SurveyResults.txt use cat to
view file."
# Now close the files

mailout.close()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,733
Latest member
LonaMonzon

Latest Threads

Top