[Twisted-Python] stmp client with multipart
![](https://secure.gravatar.com/avatar/a07b6d294d96567cea15ae7ff55df0be.jpg?s=120&d=mm&r=g)
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_selfie@scewpt.com>" mailTo = "mg@ <mg@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()
![](https://secure.gravatar.com/avatar/607cfd4a5b41fe6c886c978128b9c03e.jpg?s=120&d=mm&r=g)
On 08:36 pm, kebin70@gmail.com wrote:
How can I get something similar into a smtp client 12? multipart message
Hi Kevin, MIME and SMTP are at different layers. Twisted's SMTP client doesn't care what bytes you shove through it. They're just bytes. They can be MIME or not. Construct the bytes using the stdlib's MIME functionality if you want - once you have the bytes, the way you use them with Twisted's SMTP client is the same no matter what they are. Jean-Paul
![](https://secure.gravatar.com/avatar/607cfd4a5b41fe6c886c978128b9c03e.jpg?s=120&d=mm&r=g)
On 08:36 pm, kebin70@gmail.com wrote:
How can I get something similar into a smtp client 12? multipart message
Hi Kevin, MIME and SMTP are at different layers. Twisted's SMTP client doesn't care what bytes you shove through it. They're just bytes. They can be MIME or not. Construct the bytes using the stdlib's MIME functionality if you want - once you have the bytes, the way you use them with Twisted's SMTP client is the same no matter what they are. Jean-Paul
participants (2)
-
exarkun@twistedmatrix.com
-
Kevin Mcintyre