How can I get something similar into a smtp client 12? multipart message fn = "example.mp3" multipart = MIMEMultipart('alternative') multipart['Subject'] = 'Tutorate!' multipart['To'] = 'Selfie' multipart['From'] = 'Selfie'
text = "Hello, how are you, goodbye." textpart = MIMEText(text) multipart.attach(textpart) htmlpart = MIMEText("<html>" + text + "</html>", 'html') multipart.attach(htmlpart) part = MIMEBase('audio', "mp3") part.set_payload( open(fn,"rb").read() ) Encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(fn)) multipart.attach(part) io = StringIO.StringIO() g = Generator(io, False) g.flatten(multipart) v = io.getvalue() class SMTPTutorialClient(smtp.ESMTPClient): mailFrom = "mg_selfie@ <mg_sel...@scewpt.com>" mailTo = "mg@ <m...@scewpt.com>" def getMailFrom(self): result = self.mailFrom self.mailFrom = None return result def getMailTo(self): return [self.mailTo] def getMailData(self): print v return StringIO.StringIO(v) def sentMail(self, code, resp, numOk, addresses, log): print 'Sent', numOk, 'messages' from twisted.internet import reactor reactor.stop()
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python