00001 import smtplib, sys, MimeWriter, StringIO, base64 00002 import os 00003 ## 00004 # 00005 # Usage: 00006 # mail('somemailserver.com', 'me@example.com', 'someone@example.com', 'test', 'This is a test') 00007 # 00008 def mailWithTextAttachment(serverURL=None, sender='', to='', subject='', text=''): 00009 message = StringIO.StringIO() 00010 writer = MimeWriter.MimeWriter(message) 00011 writer.addheader('Subject', subject) 00012 writer.startmultipartbody('mixed') 00013 00014 # start off with a text/plain part 00015 part = writer.nextpart() 00016 body = part.startbody('text/plain') 00017 body.write(text) 00018 00019 # now add an attachment 00020 part = writer.nextpart() 00021 part.addheader('Content-Transfer-Encoding', 'base64') 00022 body = part.startbody('text/plain') 00023 base64.encode(open('myfile.txt', 'rb'), body) 00024 00025 # finish off 00026 writer.lastpart() 00027 00028 # send the mail 00029 smtp = smtplib.SMTP(serverURL) 00030 smtp.sendmail(sender, to, message.getvalue()) 00031 smtp.quit() 00032 00033
© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved; If you reference this document or any part of this document you must use the citation verbatim (including the link) "© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved."
Notice: This source code contained in this document is NOT open source and is NOT being distributed as open source.
122,241 lines of code and growing...