MIMEText encode error - Python 2.6.6

neubyr neubyr at gmail.com
Tue Sep 6 17:52:52 EDT 2011


I am trying to write a program which can email file's content using
smtplib. I am getting following error while using Python 2.6.6
version.

{{{
File "./killed_jobs.py", line 88, in sendmail
   msg = MIMEText(ipfile.read, 'plain')
 File "/home/ssp/sge/python/2.6.6/lib/python2.6/email/mime/text.py",
line 30, in __init__
   self.set_payload(_text, _charset)
 File "/home/ssp/sge/python/2.6.6/lib/python2.6/email/message.py",
line 224, in set_payload
   self.set_charset(charset)
 File "/home/ssp/sge/python/2.6.6/lib/python2.6/email/message.py",
line 266, in set_charset
   cte(self)
 File "/home/ssp/sge/python/2.6.6/lib/python2.6/email/encoders.py",
line 73, in encode_7or8bit
   orig.encode('ascii')
AttributeError: 'builtin_function_or_method' object has no attribute 'encode'

}}}


I am referring to email examples on the doc site
http://docs.python.org/release/2.6.6/library/email-examples.html#email-examples
. Following is the msg object part in my code:

{{{
...
...
def sendmail(inputfile):
        ipfile = open(inputfile, 'r')
        msg = MIMEText(ipfile.read, 'plain')
        ipfile.close()

...
...
}}}

I have tried setting subtype and chartype separately as mentioned here
- http://docs.python.org/release/2.6.6/library/email.mime.html, but
the error remains same. Any help on what might be wrong here?

thanks,
neuby.r



More information about the Python-list mailing list