From a42347e6e73ca32527cc1305a1f9f7c46082f40a Mon Sep 17 00:00:00 2001 From: Todd Ingarfield Date: Thu, 24 Sep 2015 10:47:19 -0500 Subject: [PATCH] corrected formating and style issues --- homeassistant/components/notify/smtp.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/notify/smtp.py b/homeassistant/components/notify/smtp.py index f4f0d4cf57b..c939737daa8 100644 --- a/homeassistant/components/notify/smtp.py +++ b/homeassistant/components/notify/smtp.py @@ -141,11 +141,13 @@ class MailNotificationService(BaseNotificationService): self.password = password self.recipient = recipient self.tries = 2 + self.mail = None self.connect() - def connect(self): + """ Connect/Authenticate to SMTP Server """ + self.mail = smtplib.SMTP(self._server, self._port) self.mail.ehlo_or_helo_if_needed() if self.starttls == 1: @@ -153,7 +155,6 @@ class MailNotificationService(BaseNotificationService): self.mail.ehlo() self.mail.login(self.username, self.password) - def send_message(self, message="", **kwargs): """ Send a message to a user. """ @@ -165,10 +166,12 @@ class MailNotificationService(BaseNotificationService): msg['From'] = self._sender msg['X-Mailer'] = 'HomeAssistant' - for attempt in range(self.tries): + for _ in range(self.tries): try: - self.mail.sendmail(self._sender, self.recipient, msg.as_string()) + self.mail.sendmail(self._sender, self.recipient, + msg.as_string()) break - except smtplib.SMTPException as e: - _LOGGER.warning('SMTP Exception sending mail: %s' % e) - self.connect() \ No newline at end of file + except smtplib.SMTPException as err: + _LOGGER.warning('SMTP Exception sending mail: {0}:{1}' + .format(err.smtp_code, err.smtp_error)) + self.connect()