Using write function within email Module to write get_payload to a file.

Chuck Amadi chuck at smtl.co.uk
Tue Jun 22 14:13:41 CEST 2004


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()






More information about the Python-list mailing list