[Twisted-Python] stmp client with multipart
Kevin Mcintyre
kebin70 at gmail.com
Fri Mar 28 14:36:11 MDT 2014
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 at scewpt.com>"
mailTo = "mg@ <mg at 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()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20140328/e1bcedee/attachment.html>
More information about the Twisted-Python
mailing list