send.py

Go to the documentation of this file.
00001 import smtplib
00002 import os
00003 from email.MIMEMultipart import MIMEMultipart
00004 from email.MIMEBase import MIMEBase
00005 from email.MIMEText import MIMEText
00006 from email.Utils import COMMASPACE, formatdate
00007 from email import Encoders
00008 
00009 def send_mail(send_from, send_to, subject, text, files=[], server="localhost"):
00010   assert type(send_to)==list
00011   assert type(files)==list
00012 
00013   msg = MIMEMultipart()
00014   msg['From'] = send_from
00015   msg['To'] = COMMASPACE.join(send_to)
00016   msg['Date'] = formatdate(localtime=True)
00017   msg['Subject'] = subject
00018 
00019   msg.attach( MIMEText(text) )
00020 
00021   for f in files:
00022     part = MIMEBase('application', "octet-stream")
00023     part.set_payload( open(file,"rb").read() )
00024     Encoders.encode_base64(part)
00025     part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f))
00026     msg.attach(part)
00027 
00028   smtp = smtplib.SMTP(server)
00029   smtp.sendmail(send_from, send_to, msg.as_string())
00030   smtp.close()
00031 
00032 

© 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...