long lines in HTML attachments

Gillou nospam at bigfoot.com
Thu Dec 27 11:24:42 EST 2001


Encode your mail body with quoted printable encoding (see doc of module
"quopri"). This way, the recipient's mail client is supposed to re-built the
lines broken by quoted-printable encodings.
I tested this successfully with OE5, Netscape messenger and StarOffice Mail.

Don't forget to add this header to your mail:

"Content-Transfer-Encoding: quoted-printable"

Or download Python 2.2 that has a new "email" standard package that handles
email messages (parse and marshal/serialize) as Python objects (easier to
handle than playing with the various packages you may need for handling
emails).
Heard that this package is available separately and may work with older
Python versions but I have no URL for this (Google for this).

HTH

--Gilles

"Iddo" <idoerg at cc.huji.ac.il> a écrit dans le message news:
7a256ac1.0112270203.77efb6f2 at posting.google.com...
> Hi,
>
> I am trying to use smtplib and mimecntl to email an attached html
> document. The trouble is that the html document contains some very
> long physical lines (500 chars). It is important that those lines be
> preserved as such, since I use <pre> formatting in the htdoc. Some
> mail clients (e.g. Pine 4.40) truncate or insert a linefeed in those
> lines, creating a mess. Any way of attaching my long-lined files and
> getting them through intact? Following is a code snippet of what I do.
> Any help would be appreciated.
>
> Thanks,
>
> Iddo
> ---------------------------------- CUT HERE --------------------------
>
>
> def email_with_attachments(to_addr, subject, msg_string, attachment):
>     f = mimecntl.MIME_document("",type='text/plain')
>     f.write(msg_string)
>     # Create the message + attachment
>     attach = mimecntl.MIME_recoder()
>     att_file = open(attachment[1],"r")
>     att_stream = att_file.read()
>     attach.write(att_stream)
>
attach['content-type']=mimecntl.MIMEField('content-type',attachment[0],
>
> name=attachment[1])
>     attach['content-length']=mimecntl.MIMEField(
>                                    'content-length',
>                                    len(att_stream))
>     attach['content-disposition']=mimecntl.MIMEField(
>                                    'content-disposition',
>                                    'attachment',
>                                     filename=attachment[1])
>     msg = mimecntl.MIME_document((f,attach),
>                                   From='myself at myserver.org',
>                                   To=to_addr,Subject=subject)
>     # send msg using smtp
>     smtp = smtplib.SMTP('localhost')
>     smtp.sendmail('myself at myserver.org',to_addr,msg.dump())
>     smtp.quit()
> if __name__ == '__main__':
>     attach_info = ('text/html','/my/html_file.html')
>     email_with_attachments('you at youraddress','hi there',attach_info)





More information about the Python-list mailing list