MIMEMultipart cuts attached file

Larry Bates lbates at swamisoft.com
Fri Sep 10 15:23:04 CEST 2004


You may want to take a look at the smtpwriter class
found at:

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

I use it extensively and it makes email creation
(with or without attachments) very easy.  At the
very least, you should be able to get some hints.

Larry Bates
Syscon, Inc.

"Achim Domma (Procoders)" <domma at procoders.net> wrote in message
news:chs8d7$p4i$05$1 at news.t-online.com...
> Hi,
>
> I try to send a mulitpart email, which should have a body and two
> attached files: a html file and a zip file. My code looks like this:
>
>
>
> msg=MIMEMultipart()
> msg['From']=sender
> msg['To']='; '.join(recipients)
> msg['Subject']=subject
> msg.epilogue=''
>
> html=file(reportFile,'rb').read()
> report=MIMEText(html,'html')
> report.add_header('Content-Disposition','attachment',filename=reportFile)
> msg.attach(report)
>
> data=file(diffFile,'rb').read()
> diff=MIMEBase('application','zip')
> diff.set_payload(data)
> encode_base64(diff)
> diff.add_header('Content-Disposition','attachment',filename=diffFile)
> msg.attach(diff)
>
> text=MIMEText("the body text",'plain')
> msg.attach(text)
>
> smtp=smtplib.SMTP('pop_server')
> smtp.set_debuglevel(0)
> smtp.sendmail(sender,recipients,msg.as_string())
> smtp.quit()
>
>
>
> The body of the mail is ok and the zip archive is also valid, but the
> end of the html is cut of most of the time.
>
> Any hints what I'm doing wrong?
>
> regards,
> Achim





More information about the Python-list mailing list