Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Email attachment problem

Reply
Thread Tools

Email attachment problem

 
 
Alan Harris-Reid
Guest
Posts: n/a
 
      04-29-2010
Hi there,

I want to send an email with an attachment using the following code
(running under Python 3.1, greatly simplified to show example)

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

msg = MIMEMultipart()
msg['From'] = from_addr
msg['To'] = to_addr
msg['Subject'] = subject
msg.attach(MIMEText(body))

fp = open(att_file)
att_msg = MIMEText(fp.read())
attachment = att_msg.add_header('Content-Disposition', 'attachment',
filename=att_file)
msg.attach(attachment)

# set string to be sent as 3rd parameter to smptlib.SMTP.sendmail()
send_string = msg.as_string()


The attachment object msg1 returns 'email.mime.text.MIMEText' object at
<address>', but when the att_msg.add_header(...) line runs the result is
None, hence the program falls-over in msg.as_string() because no part of
the attachment can have a None value. (Traceback shows "'NoneType'
object has no attribute 'get_content_maintype'" in line 118 of _dispatch
in generator.py, many levels down from msg.as_string())

Has anyone any idea what the cause of the problem might be? Any help
would be appreciated.

Alan Harris-Reid
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Binary file email attachment problem Alan Harris-Reid Python 0 05-09-2010 11:43 PM
Email Video attachment problem Fred Computer Information 1 03-17-2008 10:26 PM
Problem with Email::MIME and Email::MIME::Attachment::Stripper ecureuil Perl Misc 0 05-28-2006 01:47 AM
attachment email script problem Shawn Perl Misc 0 02-06-2004 04:20 AM
attachment in email problem John Computer Support 3 08-21-2003 05:49 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57