BRGVersion:6 revision:$Revision$ UUID:b585f926-bc5e-4c09-8dc7-1490de92b7cb timestamp:1510066041 baselib:core baselib:lal1 begin:graphprops propdef:GraphName|string|1||None propdef:AutomationHost|string|1||None propdef:AutomationPort|string|1||None propdef:AutomationUsername|string|1||None propdef:AutomationPassword|password|1||None propdef:smtpServer|string|1||None prop:GraphName=LM_List_Users prop:AutomationHost=localhost prop:AutomationPort={{%ls.brain.webapp.port%}} prop:AutomationUsername=admin encrypted:simple=nFZhmIpdcU/tLMZFEdRHethHrEDx+VB7RwHjepm0jxk= prop:smtpServer=mailrelay.comcast.com end:graphprops libnode:SMTP_Mail bretype:core::Python editor:Label=SMTP Mail editor:handle=56f1989f708b3a66 editor:sortkey=49ef3a00051d2f02_2 prop:AUTHREQUIRED=false prop:ColumnOrder={{^^}} prop:Enabled=true prop:GroupBy={{^^}} prop:Mandatory=false prop:Python2Implementation=<\r\n" message = message + "\r\n" if self.bodymessage != '': message = message + self.bodymessage if self.bodytext != '': message = message + "\r\n\r\n"+ self.bodytext message = message + "\r\n" message = message + "\r\n" msg = MIMEMultipart() msg['From'] = Sender msg['To'] = Recipients msg['Subject'] = Subject msg.attach(MIMEText(message,'html')) files=[] if self.properties.getString('ls.brain.smtpmail.filestoattach',"") <> '': t = self.properties.getString('ls.brain.smtpmail.filestoattach',"").split(",") files.extend(t) if self.attachFiles <> '': t = self.attachFiles.split(",") files.extend(t) #self.logInfo("C="+str(t)) for file in files: bad=False try: f = open(file,"rb") except IOError: bad = True if not bad: part = MIMEBase('application', "octet-stream") part.set_payload( f.read() ) Encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(file)) msg.attach(part) server = smtplib.SMTP(smtpServer, smtpPort) #server.set_debuglevel(1) server.ehlo() if SSLREQUIRED: server.starttls() server.ehlo() if AUTHREQUIRED: server.login(smtpUser,smtpPass) if Recipients != '': server.sendmail('', Recipients.split(','), msg.as_string() ) server.rset() server.quit() server.close() def setemailheader(self): self.header = '' for idx,field in enumerate(self.columnOrder): self.header = self.header + '' + field.strip() def setemailrcp2(self,rec): if len(self.inputs) > 0 and self.rcp2f != '': self.Recipients2 = rec[self.rcp2f] else: self.Recipients2 = '' def setemailbody(self): self.bodytext = '\n' if self.sendHeaders or true: self.bodytext = self.bodytext + self.header + '\n' def closeandsendemail(self): if self.bodytext != '': self.bodytext = self.bodytext + '
\n' if self.bodytext != '' or self.sendZeroInput: sendmail(self) setemailbody(self) else: self.logInfo('Zero Input - email not sent') def setup(brainNodeControlObj, BrainNodeClass): class BrainNode(BrainNodeClass): def initialize(self): super(BrainNode, self).initialize() self.sendZeroInput = self.properties.getBool('ls.brain.smtpmail.sendZeroInput') self.sendHeaders = self.properties.getBool('ls.brain.smtpmail.sendHeaders',True) self.columnOrder = self.properties.getString('ls.brain.smtpmail.columnOrder','').split(',') self.Recipients = self.properties.getString('ls.brain.smtpmail.Recipients','') self.rcp2f = self.properties.getString('ls.brain.smtpmail.RecipientsField','') self.attachFileNameField = self.properties.getString('ls.brain.smtpmail.attachFileNameField',"") #self.logInfo("A="+self.attachFileNameField) if self.Recipients=='' and self.rcp2f=='': raise Exception, 'No recipients specified' return False self.message = '' self.header = '' self.attachFiles='' fn = self.properties.getString('ls.brain.smtpmail.Message','') if fn != '': f=open(fn,"r") self.message = f.read() self.bodymessage=self.message self.reccount=0 if len(self.inputs) > 0: setemailheader(self) rec = self.inputs[0].read() if rec: self.reccount=1 if self.attachFileNameField <> "": self.attachFiles=rec[self.attachFileNameField] else: rec = '' setemailrcp2(self,rec) setemailbody(self) if len(self.inputs) > 0: gbv='_all_' gb = self.properties.getString('ls.brain.smtpmail.GroupBy','') if gb != '': gbv=rec[gb] if rec: self.bodymessage=substituteMessageVars(self,rec) setemailrcp2(self,rec) while rec: if self.attachFileNameField <> "": #self.logInfo("D1="+str(rec["FileName"])) #self.logInfo("D2="+str(self.attachFileNameField)) self.attachFiles = str(rec[str(self.attachFileNameField)]) #self.logInfo("D3="+str(self.attachFiles)) self.bodytext = self.bodytext + '\n' for idx,field in enumerate(self.columnOrder): if field.strip() <> '': self.bodytext = self.bodytext+ '' + str(rec[field.strip()]) + '\n' rec = self.inputs[0].read() self.reccount=self.reccount+1 if gb <> '': if rec and rec[gb]<>gbv: closeandsendemail(self) self.bodymessage=substituteMessageVars(self,rec) setemailrcp2(self,rec) gbv=rec[gb] time.sleep(1) if len(self.inputs) > 0: if self.reccount > 0: closeandsendemail(self) else: self.logInfo("No records to send") else: closeandsendemail(self) def finalize(self, val): super(BrainNode, self).finalize(val) def pump(self, quant): while quant.permitsRunning(self): return False return True return BrainNode EOX prop:PythonCodeOnServer=true prop:RecipientsField={{^^}} prop:SSLREQUIRED=false prop:SendWithZeroInput=true prop:Sender=none@domain.com prop:Subject=Test Email prop:ToolCode=</dev/null") def finalize(self, val): ''' Called at node end, after last pump call. ''' super(BrainNode, self).finalize(val) def pump(self, quant): while quant.permitsRunning(self): return False return BrainNode EOX editor:XY=450,130 editor:propdef=DelayBetweenCommands|string|1||None editor:propdef=LogFile|string|1|ls.brain.node.ExecuteShellCommand.LogFile|None end:Remove_Attached_file node:Filter bretype:core::Filter editor:handle=56f19b9f5af25f63 editor:sortkey=53ab0411508c058c input:@40fd2c74167f1ca2/=Static_Data.40fe6c55598828e5 output:@40fd2c7420761db6/= prop:Script=< "" and "{{^DeleteExcel^}}"== "true" then abort("Delete is turned ON, so FileToAttach should be {"+"{^^}}") if "{{^FileToAttach^}}" == "" and "{{^Message^}}".strFindI("{{^ExcelFileName^}}") == -1 then abort("ExcelFileName missing from Message") EOX editor:XY=310,220 end:Filter node:Static_Data bretype:core::Static Data editor:handle=56f19b9f37210f25 editor:sortkey=53ab04183630752d output:@40fe6c55598828e5/= inclock:/=Output_Excel prop:StaticData=< 0 and LOGIN_STATUS <> 200 then abort(str(LOGIN_STATUS_MESSAGE)) EOX editor:XY=180,230 end:Throw_Error_on_Failure_2 end:Login_2 libnode:LAE_Properties bretype:core::Python editor:Label=LAE Properties editor:handle=5577ce5a63070365 editor:sortkey=551b46202ca15360 output:4649fd1f3e8079a3/= prop:Python2Implementation=<-1 then LDAP_id=str(field("1:"+str(t+1))) else LDAP_id=str(null) emit LDAP_id EOX editor:XY=480,80 end:Drop_Columns node:Sort bretype:core::Sort editor:handle=56f197fd4f37728d editor:sortkey=56f197fd4f37728d input:@40fd2c743ebf4304/=Lookup_2.40fd2c7445835585 output:@40fd2c746a2a3b47/= prop:CompareOrderExpr=<