def send(self, ignoreSend): self._genHtmlCtn() self._getTextCtn() notifyFile = open("%s/notify.html" % TestCase.getWorkDir(), 'w') notifyFile.write(self.html) notifyFile.close() if ignoreSend or not TestCase.checkParam('email.enable', 'True'): logger.info("No email notification") return if TestCase.isForceSkip(): emailTo = self.emailFrom else: emailTo = TestCase.getParamEval('email.toList') if emailTo is None: emailTo = [self.emailFrom] else: emailTo.append(self.emailFrom) msg = MIMEMultipart('alternative') msg['Subject'] = "[Test Result] %s" % TestCase.testCtx.desc msg['From'] = self.emailFrom msg['To'] = ';'.join(emailTo) part1 = MIMEText(self.text, 'plain') part2 = MIMEText(self.html, 'html') msg.attach(part1) msg.attach(part2) try: server = smtplib.SMTP(self.stmpSvr) # connect, no login step except: logger.error('Failed to connect the email server, %s', self.stmpSvr) return False failed = server.sendmail(self.emailFrom, emailTo, msg.as_string()) server.quit() if failed: # smtplib may raise exceptions logger.error("Failed to send mail due to %s", failed) return False else: logger.info("Send test result email to %s", emailTo) return True
def _getInfoSec(self): while True: infos = TestCase.getParamEval('email.info') bench = TestCase.getParamExactEval('bench') if infos is None and bench is None: break if bench is not None: if isinstance(bench, basestring): bench = [bench] if infos is None: infos = ['Test Bench', bench['desc']] else: infos.append(['Test Bench', bench['desc']]) for info in infos: self.html += '<h1>%s</h1><ul style="list-style-type:square">' % info[ 0] for item in info[1]: self.html += '<li>%s</li>' % item self.html += '</ul>\n' break