Código Python:
Ver original
def SendMail():#to, subject, text, files=[],server="localhost"): numFiles= os.listdir('~/ReportingTool/Logs/') dirFil='~/ReportingTool/Logs/' dirOld='~/ReportingTool/Logs/Old/' dirEnc='~/ReportingTool/Encfiles/' for cont in numFiles: if (os.path.isfile(os.path.join(dirFil,cont))): # Encrypt all files to send via email filin=dirFil+cont filout=dirEnc+cont Encrypt("xxxxxxxx", filin, filout) filout=dirEnc+"25-05-2010.Tuesday" # Move files to dir Old mvin=os.path.join(dirFil,cont) mvout=os.path.join(dirOld,cont) shutil.move(mvin,mvout) def Send(to, subject, text, files,server="localhost"): # assert type(to)==list # assert type(files)==list fro = "[email protected]" msg = MIMEMultipart() msg['From'] = fro msg['To'] = COMMASPACE.join(to) msg['Date'] = formatdate(localtime=True) msg['Subject'] = subject msg.attach( MIMEText(text) ) part = MIMEBase('application', "octet-stream") part.set_payload( open(files,"rb").read() ) Encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="%s"'% os.path.basename(files)) msg.attach(part) smtp = smtplib.SMTP(server) error=True if (smtp.sendmail(fro, to, msg.as_string())): error=False; smtp.close() if (error==False): return True else: return False