Help - email library not working as expected

D

Deathstar

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top