示例#1
0
文件: controller.py 项目: bkjems/gdc
    def send_text(self, msg):
        self.logger = logging.getLogger(__name__)

        if Utils.is_too_early():
            return

        #logging.info("SM - %s" % (msg))
        try:
            if self.use_smtp:
                config = self.config['alerts']['smtp']
                server = smtplib.SMTP(config["smtphost"], config["smtpport"])
                if (config["smtp_tls"] == True):
                    server.starttls()
                    server.login(config["username"], config["password"])
                    mg = MIMEText(msg)
                    server.sendmail('from', config["to_email"], mg.as_string())
        except smtplib.SMTPException as e:
            self.logger.error("Error: unable to send gmail text %s", e)
        except:
            self.logger.error("Main Exception: %s", sys.exc_info()[0])
        finally:
            try:
                server.quit()
            except smtplib.SMTPServerDisconnected as sd:
                self.logger.error("sd Error: .quit() failed %s", sd)
                server.close()
            except:
                self.logger.error("final Exception: %s", sys.exc_info()[0])
 def send_email(self, title, message):
     if self.use_smtp:
         syslog.syslog("Sending email message")
         config = self.config['alerts']['smtp']
         server = smtplib.SMTP(config["smtphost"], config["smtpport"])
         if (config["smtp_tls"] == "True") :
             server.starttls()
         server.login(config["username"], config["password"])
         server.sendmail(config["username"], config["to_email"], message)
         server.close()
 def send_email(self, title, message):
     if self.use_smtp:
         syslog.syslog("Sending email message")
         config = self.config['alerts']['smtp']
         server = smtplib.SMTP(config["smtphost"], config["smtpport"])
         if (config["smtp_tls"] == "True") :
             server.starttls()
         server.login(config["username"], config["password"])
         server.sendmail(config["username"], config["to_email"], message)
         server.close()
 def send_closedoor_message(self):
    syslog.syslog("Sending close door message.")
    config = self.config['smtp']
    server = smtplib.SMTP(config["smtphost"], config["smtpport"])
    if (config["smtp_tls"] == "True") :
        server.starttls()
    server.login(config["username"], config["password"])
    message = "Your garage door %s have been closed." % self.name
    server.sendmail(config["username"], config["to_email"], message)
    server.close() 
 def send_opendoor_message(self, opentime):
     syslog.syslog("Sending open door message. (%s)" % opentime)
     config = self.config['smtp']
     server = smtplib.SMTP(config["smtphost"], config["smtpport"])
     if (config["smtp_tls"] == "True") :
         server.starttls()
     server.login(config["username"], config["password"])
     message = "Your garage doors have been open for %s." % elapsed_time(100+opentime)
     server.sendmail(config["username"], config["to_email"], message)
     server.close()
     self.msg_sent = True    
 def send_opendoor_message(self, opentime):
     syslog.syslog("Sending open door message. (%s)" % opentime)
     config = self.config['smtp']
     server = smtplib.SMTP(config["smtphost"], config["smtpport"])
     if (config["smtp_tls"] == "True"):
         server.starttls()
     server.login(config["username"], config["password"])
     message = "Your garage doors have been open for %s." % elapsed_time(
         100 + opentime)
     server.sendmail(config["username"], config["to_email"], message)
     server.close()
     self.msg_sent = True
 def send_email(self, title, message):
     try:
         if self.use_smtp:
             syslog.syslog("Sending email message")
             config = self.config['alerts']['smtp']
             
             message = MIMEText(message)
             message['Date'] = formatdate()
             message['From'] = config["username"]
             message['To'] = config["to_email"]
             message['Subject'] = config["subject"]
             message['Message-ID'] = make_msgid()
             
             server = smtplib.SMTP(config["smtphost"], config["smtpport"])
             if (config["smtp_tls"] == "True") :
                 server.starttls()
             server.login(config["username"], config["password"])
             server.sendmail(config["username"], config["to_email"], message.as_string())
             server.close()
     except Exception as inst:
         syslog.syslog("Error sending email: " + str(inst))
示例#8
0
 def send_email(self, title, message):
     try:
         if self.use_smtp:
             syslog.syslog("Sending email message")
             config = self.config['alerts']['smtp']
             
             message = MIMEText(message)
             message['Date'] = formatdate()
             message['From'] = config["username"]
             message['To'] = config["to_email"]
             message['Subject'] = config["subject"]
             message['Message-ID'] = make_msgid()
             
             server = smtplib.SMTP(config["smtphost"], config["smtpport"])
             if (config["smtp_tls"] == "True") :
                 server.starttls()
             server.login(config["username"], config["password"])
             server.sendmail(config["username"], config["to_email"], message.as_string())
             server.close()
     except Exception as inst:
         sys.syslog("Error sending email: " + str(inst))