Help - email library not working as expected

Deathstar deathstar at altern.org
Thu Jun 17 14:18:14 CEST 2004


Hi,

I'm having some problems using the Python email library. I want to write a mail 

that has a body, and an attachment with it. From what I understand, the 

set_payload() function would be specify the body, and attach() would specify a 

MIME attachment Message. 

However this does not work. I get an error saying : 
'str' object has no attribute 'append'

I'm doing this with Python 2.3.2 on Windows XP SP1. What am I doing wrong here? 

How do u specify the body and the attachment to the mail?

======== Code Snippet Start ======== 
my_mail=Message()
my_mail['From']=addr_frm
my_mail['To']=addr_to
my_mail['Subject']=sub
my_mail.set_payload(bdy.read()) #Body of the mail


attachment=MIMEMultipart(mimetypes.guess_type(att_name))
att=open(att_name)
attachment.set_payload(att.read()) #The attachment

my_mail.attach(attachment)

print my_mail.as_string()
======== Code Snippet End ========

Regards,
Deathstar



More information about the Python-list mailing list