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()
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
ah, it just seems like the next smtp client (potentially 12) from the samples could be multipart mime.
On Fri, Mar 28, 2014 at 3:12 PM, exarkun@twistedmatrix.com wrote:
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
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python