We created a module called sendmail which email html content. Each of application dumps data from the datastructure into html format and then calls this module
def createhtmlmail( html, text, subject ): """Create a mime-message that will render HTML in popular MUAs, text in better ones""" import MimeWriter import mimetools import cStringIO out = cStringIO.StringIO() # output buffer for our message htmlin = cStringIO.StringIO(html) writer = MimeWriter.MimeWriter(out) # # set up some basic headers... we put subject here # because smtplib.sendmail expects it to be in the # message body # writer.addheader("Subject", subject) writer.addheader("MIME-Version", "1.0") # # start the multipart section of the message # multipart/alternative seems to work better # on some MUAs than multipart/mixed # writer.startmultipartbody("alternative") writer.flushheaders() # # the plain text section # if text != None: txtin = cStringIO.StringIO(text) subpart = writer.nextpart() subpart.addheader("Content-Transfer-Encoding", "quoted-printable") pout = subpart.startbody("text/plain", [("charset", 'us-ascii')]) mimetools.encode(txtin, pout, 'quoted-printable') txtin.close() # # start the html subpart of the message # subpart = writer.nextpart() subpart.addheader("Content-Transfer-Encoding", "quoted-printable") # # returns us a file-ish object we can write to # pout = subpart.startbody("text/html", [("charset", 'us-ascii')]) mimetools.encode(htmlin, pout, 'quoted-printable') htmlin.close() # # Now that we're done, close our writer and # return the message body # writer.lastpart() msg = out.getvalue() out.close() #print msg return msg def sendmail (sender,to,subject,htmlFilename): import smtplib f = open(htmlFilename, 'r') html = f.read() f.close() message = createhtmlmail(html, None, subject) server = smtplib.SMTP("mta-hub") server.sendmail(sender, to, message) server.quit()
Great blog. Keep up the good work. python training in Chennai
At this time, if you can use good medicinal materials and ingredients to strengthen hormones,Creative Voucher Provider In NSW will be able to retain your youth and enjoy masculine power.
Nice info, I am very thankful to you for sharing this important knowledge. This information is helpful for everyone. Read more info about Toefl Preparation Courses Hk. So please always share this kind of information. Thanks.
You are providing good knowledge. It is really helpful and factual information for us and everyone to increase knowledge. about Learn Python Programming for Kids .Continue sharing your data. Thank you.