[Tutor] E-mail format suggestions please

Mark Rowe mark21rowe@yahoo.com
Sun, 22 Apr 2001 17:02:46 +1200


I think it would be a good idea to use the MimeWriter and smtplib modules to
build and send the message with, as you mentioned, an attached HTML table.
This would then avoid having to use COM.  Some example code is below.

Mark Rowe

--- Example Code ---

import sys, smtplib, MimeWriter, base64, StringIO

message = StringIO.StringIO()
writer = MimeWriter.MimeWriter(message)
writer.addheader('Subject', 'The kitten picture')
writer.startmultipartbody('mixed')

# start off with a text/plain part
part = writer.nextpart()
body = part.startbody('text/plain')
body.write('This is a picture of a kitten, enjoy :)')

# now add an image part
part = writer.nextpart()
part.addheader('Content-Transfer-Encoding', 'base64')
body = part.startbody('image/jpeg')
base64.encode(open('kitten.jpg', 'rb'), body)

# finish off
writer.lastpart()

# send the mail
smtp = smtplib.SMTP('smtp.server.address')
smtp.sendmail('from@from.address', 'to@to.address', message.getvalue())
smtp.quit()



----- Original Message -----
From: "Phil Bertram" <phil.bertram@clear.net.nz>
To: <tutor@python.org>
Sent: Sunday, April 22, 2001 8:11 AM
Subject: [Tutor] E-mail format suggestions please


Hello,

Off topic I know but someone may be able to help.

I have been working on a little program that tracks a sports competition.

I need to E-mail weekly results to a 100 or so of people.

Originally I created a table in the body of the E-mail. The table was
constructed using spaces to line up the columns. The problem is that some
recieving E-mail programs default to a proportional font. Thus every thing
goes out of line.

Is their something in the MIME spec. or other, where the default font can be
specified for the recieving E-mail program?

My current solution is to create the output in HTML and attatch it to the
E-mail.

I am using win32com modules and Microsoft Exchange to do the E-mail part of
the program. Running NT4

Thanks in advance
Phil B

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com