mime multipart messages
Clarence Gardner
clarence at netlojix.com
Thu Feb 28 20:53:11 EST 2002
In article <mailman.1014923455.7488.python-list at python.org>,
Glenn Stauffer <python at dejazzd.com> writes:
> I'm using the MimeWriter module to attach a file, submitted through an html
> form, to an email message. When I do this and send mail to a unix machine
> and read the mail with mutt or kmail, the file is attached to the message as
> I would expect. However, when the message is opened on a Mac or Windows
> machine, the file is mixed into the body of the message.
>
> This is the code I use to construct the message:
>
> -------------------------------------------------------------------------------
>
> message = StringIO.StringIO()
> writer = MimeWriter.MimeWriter(message)
> writer.addheader('Subject', mail_subject)
> writer.startmultipartbody('mixed')
>
> part=writer.nextpart()
> body = part.startbody('text/plain')
> body.write(msgbody)
>
> part=writer.nextpart()
> part.addheader('Content-Type','application/mixed')
> part.addheader('Content-Transfer-Encoding', 'base64')
> part.addheader('Content-Disposition','attachment; filename=%s' %
> form['file'].filename)
> body = part.startbody('application/binary')
> base64.encode(open(tmpfile,'rb'), body)
>
> writer.lastpart()
>
> -------------------------------------------------------------------------------
>
> This is how the file looks when someone opens it with Eudora on a Windows PC:
>
> --130.58.64.30.99.29450.1014921136.814.11340
> Content-Type: text/plain
>
>
> --130.58.64.30.99.29450.1014921136.814.11340
> Content-Type: application/binary
> Content-Type: application/mixed
> Content-Transfer-Encoding: base64
> Content-Disposition: attachment; filename=README
>
> PT09PT09PT09PT09PT09PT09PT0NClRoZSB4bWxycGNsaWIgbW9kdWxlDQo9PT09PT09PT09PT09
> PT09PT09PQ0KDQpUaGlzIGtpdCBjb250YWlucyBhIFB5dGhvbiBpbXBsZW1lbnRhdGlvbiBmb3Ig
>
> -------------------------------------------------------------------------------
>
> Anyone have any thoughts on what I'm doing wrong or where to look to figured
> this problem out?
>
> Thanks,
>
> Glenn
>
--
Clarence Gardner
Software Engineer
NetLojix Communications
clarence at netlojix.com
More information about the Python-list
mailing list