Email library attachment problem
Brad Clements
bkc at Murkworks.com
Tue Jan 8 13:33:21 EST 2002
Are you trying to send HTML email with embedded images?
I'm working up a HOW-TO for www.zope.org on how to do this using the email
package (both inside, and outside Zope).
Not sure why your example isn't working, but perhaps you need multi-part
alternative for sending plain text.
--
Brad Clements, DevNet Sysop 5
Developer Network Sysop Team
"Bob McCallister" <hcsrpm at texlife.com> wrote in message
news:423bea0d.0201080945.136c5048 at posting.google.com...
> I'm using email .96 with python 2.0. I read the bug about only
> attaching one file and getting an error. Am I missing something or do
> I have to attach a dummy file first, then attach my text, followed by
> any other attachments. When I attach two files, only the second one
> gets delivered. When I attach three files, only the last two get
> delivered, etc. Here is the program (modified from the examples
> section of the doc)
>
> # Import smtplib for the actual sending function
> import smtplib
>
> # Here are the email pacakge modules we'll need
> from email import Encoders
> from email.MIMEText import MIMEText
> from email.MIMEImage import MIMEImage
> from email.MIMEBase import MIMEBase
>
> COMMASPACE = ', '
>
> # Create the container (outer) email message.
> me = 'hcsrpm at texlife.com'
> family = ['hcsrpm']
> msg = MIMEBase('multipart', 'mixed')
> msg['Subject'] = 'Python email test'
> msg['From'] = me
> msg['To'] = COMMASPACE.join(family)
> msg.preamble = 'Message and Two jpg images attached'
> # Guarantees the message ends in a newline
> msg.epilogue = ''
>
> fp = open('messagetext')
> text = MIMEText(fp.read(), _encoder=Encoders.encode_quopri)
> msg.attach(text)
> fp.close
>
> # Attach images
> attachfiles=['DV1.jpg','DV2.jpg']
> for file in attachfiles:
> # Open the files in binary mode. Let the MIMEIMage class
> automatically
> # guess the specific image type.
> fp = open(file, 'rb')
> img = MIMEImage(fp.read())
> fp.close()
> msg.attach(img)
>
> # Send the email via our own SMTP server.
> s = smtplib.SMTP()
> s.connect()
> s.sendmail(me, family, msg.as_string(0))
> s.close()
>
> With this I get the two image files, but not the contents of the file
> 'messagetext.' If I skip the text attachment, I only get 'DV2.jpg.'
>
> Thanks,
> Bob McCallister
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
Check out our new Unlimited Server. No Download or Time Limits!
-----== Over 80,000 Newsgroups - 19 Different Servers! ==-----
More information about the Python-list
mailing list