473,320 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 1338
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Adam Steinberger | last post by:
Hey, I'm currently working on an address book using classes that will take and email address and a name and save it in a certain format in a text file. Could you help me! I'm sure my code should...
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
0
by: moondaddy | last post by:
I want to build a main template page for my website that other pages can inherit from so they'll all have the same look and feel. I found some good links in some other postings based on the...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
2
by: martoncho | last post by:
Hi all, I am facing what is for me a really complicated situation. I program C but not this advanced (I mean direct hardware access etc). Here is the background: I am using DJGPP. I am...
0
by: Jack Wu | last post by:
Hi I've spent a good majority of my day trying to figure out how to have PIL 1.1.5 working on my OSX 10.3.9_PPC machine. I'm still stuck and I have not gotten anywhere. Could somebody please...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
3
by: Brad | last post by:
I have an aspx page that is sending pdf files to client browsers: it uses a filestream to read the pdf file and response.binarywrite to send content to the browser. This has worked great for years...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.