469,343 Members | 5,388 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

Help - email library not working as expected

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
Jul 18 '05 #1
1 1252
I have found that the SmtpWriter class "hides" all the
complexity in creating emails like you want to send.

Check it out here:

http://motion.sourceforge.net/related/send_jpg.py

HTH,
Larry Bates
Syscon, Inc.

"Deathstar" <de*******@altern.org> wrote in message
news:dd*************************@posting.google.co m...
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

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Adam Steinberger | last post: by
8 posts views Thread by intrepid_dw | last post: by
reply views Thread by moondaddy | last post: by
1 post views Thread by Rahul | last post: by
2 posts views Thread by martoncho | last post: by
reply views Thread by Jack Wu | last post: by
53 posts views Thread by souporpower | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.