corrected formating and style issues
This commit is contained in:
parent
b2999ae325
commit
a42347e6e7
1 changed files with 10 additions and 7 deletions
|
@ -141,11 +141,13 @@ class MailNotificationService(BaseNotificationService):
|
||||||
self.password = password
|
self.password = password
|
||||||
self.recipient = recipient
|
self.recipient = recipient
|
||||||
self.tries = 2
|
self.tries = 2
|
||||||
|
self.mail = None
|
||||||
|
|
||||||
self.connect()
|
self.connect()
|
||||||
|
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
|
""" Connect/Authenticate to SMTP Server """
|
||||||
|
|
||||||
self.mail = smtplib.SMTP(self._server, self._port)
|
self.mail = smtplib.SMTP(self._server, self._port)
|
||||||
self.mail.ehlo_or_helo_if_needed()
|
self.mail.ehlo_or_helo_if_needed()
|
||||||
if self.starttls == 1:
|
if self.starttls == 1:
|
||||||
|
@ -153,7 +155,6 @@ class MailNotificationService(BaseNotificationService):
|
||||||
self.mail.ehlo()
|
self.mail.ehlo()
|
||||||
self.mail.login(self.username, self.password)
|
self.mail.login(self.username, self.password)
|
||||||
|
|
||||||
|
|
||||||
def send_message(self, message="", **kwargs):
|
def send_message(self, message="", **kwargs):
|
||||||
""" Send a message to a user. """
|
""" Send a message to a user. """
|
||||||
|
|
||||||
|
@ -165,10 +166,12 @@ class MailNotificationService(BaseNotificationService):
|
||||||
msg['From'] = self._sender
|
msg['From'] = self._sender
|
||||||
msg['X-Mailer'] = 'HomeAssistant'
|
msg['X-Mailer'] = 'HomeAssistant'
|
||||||
|
|
||||||
for attempt in range(self.tries):
|
for _ in range(self.tries):
|
||||||
try:
|
try:
|
||||||
self.mail.sendmail(self._sender, self.recipient, msg.as_string())
|
self.mail.sendmail(self._sender, self.recipient,
|
||||||
|
msg.as_string())
|
||||||
break
|
break
|
||||||
except smtplib.SMTPException as e:
|
except smtplib.SMTPException as err:
|
||||||
_LOGGER.warning('SMTP Exception sending mail: %s' % e)
|
_LOGGER.warning('SMTP Exception sending mail: {0}:{1}'
|
||||||
|
.format(err.smtp_code, err.smtp_error))
|
||||||
self.connect()
|
self.connect()
|
Loading…
Add table
Reference in a new issue