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@ <[email protected]>"
mailTo = "mg@ <[email protected]>"
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
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python