def debug_error_Call(message): conf = Config() config = conf.eVerify() logging.info("- Debug -") smtp_server = config["SERVER"] smtp_port = config["PORT"] smtp_username = config["USERNAME"] smtp_password = config["PASSWORD"] smtp_from = config["FROM"] smtp_to = config["D_TO"] smtp_cc = config["D_CC"] smtp_bcc = config["D_BCC"] smtp_subject = config["D_SUBJECT"] smtp_body = config["D_BODY"] logging.info(message) try: logging.info("- DEBUG error is sending...") server = SMTP(smtp_server, smtp_port) server.set_debuglevel(True) msg = MIMEMultipart() msg["From"] = smtp_from msg["To"] = "; ".join(smtp_to) emails = [smtp_to] if smtp_cc is not "": msg["CC"] = "; ".join(smtp_cc) emails += smtp_cc if smtp_bcc is not "": msg["BCC"] = "; ".join(smtp_bcc) emails += smtp_bcc msg["Subject"] = smtp_subject body = MIMEText(message + smtp_body, "html") msg.attach(body) # logging.debug(msg.as_string()) # identify ourselves, prompting server for supported features server.ehlo() # If we can encrypt this session, do it if server.has_extn("STARTTLS"): server.starttls() server.ehlo() # re-identify ourselves over TLS connection logging.info("- DEBUG AUTOKILL sending in secure tunnel...") server.login(smtp_username, smtp_password) server.sendmail(smtp_from, emails, msg.as_string()) logging.info("- DEBUG ERROR MAIL sent....................................OK") logging.info("- Error has been notified.....................................OK") except SMTPException, sme: logging.error("- Error notifying results by email: %s" % sme) logging.debug("- Debug error have been NOT notified.....................FAIL") raise OSError
def interceptCall(f): now = datetime.datetime.now() now_month = now.month # data format: YYYYMMDD if int(now_month) < 10: now_month = "0" + str(now.month) today = str(now.year) + str(now_month) + str(now.day) conf = Config() config = conf.eVerify() logging.info("- INTERCEPT STARTED -") smtp_server = config["SERVER"] smtp_port = config["PORT"] smtp_username = config["USERNAME"] smtp_password = config["PASSWORD"] smtp_from = config["FROM"] smtp_to = config["E_TO"] smtp_cc = config["E_CC"] smtp_bcc = config["E_BCC"] smtp_subject = config["E_SUBJECT"] smtp_body = config["E_BODY"] file_name = config["E_ATTACHMENT"] + str(today) + ".txt" file_attach = f try: logging.info("- INTERCEPT is sending...") server = SMTP(smtp_server, smtp_port) server.set_debuglevel(True) msg = MIMEMultipart() msg["From"] = smtp_from msg["To"] = "; ".join(smtp_to) emails = [smtp_to] if smtp_cc is not "": msg["CC"] = "; ".join(smtp_cc) emails += smtp_cc if smtp_bcc is not "": msg["BCC"] = "; ".join(smtp_bcc) emails += smtp_bcc msg["Subject"] = smtp_subject body = MIMEText(smtp_body, "html") msg.attach(body) try: logging.info("- Attaching file: {0}".format(str(file_attach))) with open(file_attach, "rb") as fil: part = MIMEApplication(fil.read(), "text/plain", filename=file_name) part.add_header("Content-Disposition", "attachment", filename=file_name) msg.attach(part) except OSError, e: logging.error("- Error walking dir '%s': %s" % (dir, e)) raise OSError # identify ourselves, prompting server for supported features server.ehlo() # If we can encrypt this session, do it if server.has_extn("STARTTLS"): server.starttls() server.ehlo() # re-identify ourselves over TLS connection logging.info("- INTERCEPT CALL sending in secure tunnel...") server.login(smtp_username, smtp_password) server.sendmail(smtp_from, emails, msg.as_string()) logging.info("- INTERCEPT email sent........................................OK") logging.info("- Results have been notified..................................OK")