simple script to read and output Mailbox body to file.
Chuck Amadi
chuck at smtl.co.uk
Wed Jun 9 06:46:45 EDT 2004
Hi again
I get output desired .Now to parse the fileobject and all body messages to an
external File named SurveyResults.txt
Is this the correct way to go about it .
for mail in mbox:
# body = mail.get_payload()
# bodies.append(body)
# msg = mail.message_from_file(mail)
print 'mail'
print mail['Subject']
print mail.get_content_type()#text/plain
print mail.get_payload()
# break # just look at one message
# The File SurveyResults.txt must all ready exist.
output = open("SurveyResults.txt", 'w') # mode 'w' means open the file for
writ-ing (any data already in the file will be erased)
mailout = mail.get_payload()
output. writelines(mailout)
output. close() # this is at end of the script
Here's my error but I thought mail is my file
Traceback (most recent call last):
File "getSurveyMailRev2.py", line 37, in ?
mailout = mail.get_payload()
NameError: name 'mail' is not defined
More information about the Python-list
mailing list