Python/SMTP

From Fundamental Ramen
< Python
Revision as of 09:39, 5 June 2018 by Tacoball (talk | contribs) (Created page with "<source lang="python"> try: HOST = self.config['smtp_host'] PORT = self.config['smtp_port'] TIMEOUT = self.config['smtp_timeout'] with...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
try:
          HOST = self.config['smtp_host']
          PORT = self.config['smtp_port']
          TIMEOUT = self.config['smtp_timeout']
          with smtplib.SMTP(HOST, PORT, timeout = TIMEOUT) as smtp:
              FROM = self.config['smtp_mail_from']
              RCPT = self.config['smtp_rcpt_to']
              smtp.set_debuglevel(2)
              smtp.sendmail(FROM, RCPT, source)
          self.smtp_state = SmtpState.CONNECTED
        except smtplib.SMTPConnectError:
          self.smtp_state = SmtpState.CONN_REFUSED
          #logger.error('Connection refused.')
        except smtplib.SMTPServerDisconnected:
          self.smtp_state = SmtpState.CONN_TIMEOUT
          #logger.error('Connection timeout.')
        except:
          self.smtp_state = SmtpState.CONN_UNKNOWN