Howto use email module and write the get_payload to a file
chuck.amadi at ntlworld.com
Tue Jun 22 00:07:59 CEST 2004
Hi I have managed to print the output of the get_payload to screen
but I need to write to a file as I only require the email body messages
from the mailbox.My script using the fp.readlines() function writes the
entire contents of the mailbox of cause including the headers of the
emails I do not want.
I have tried a few things but I cant get to my goal.Any ideas or
pointers I need only the email body and I cant figute out why I can
using the print statement but get those results to a file.
fp = file ("/var/spool/mail/chucka")
mbox = mailbox.UnixMailbox(fp, email.message_from_file)
# list of body messages.
bodies = 
# mail is the file object
for mail in mbox:
mailout = file("/home/chucka/pythonScript/SurveyResults1.txt","r")
fp = open("/var/spool/mail/chucka")
mb = mailbox.UnixMailbox(fp, email.message_from_file)
#for bdymsg in fp.xreadlines():
#for bdymsg in fp.readlines():
#for msgbodies in mb:
# bdymsg = mail.get_payload()
for bmsg in mb:
bmsg = get_payload()
# bmsg = [get_payload]
print "mailbox file copied...to SurveyResults.txt"
# Now close the files
More information about the Python-list