Allow multiple recipients for SMTP notify (#7319)
The existing (singular) configuration keyword is kept for compatibility.
This commit is contained in:
1 parent
0298522fd5
commit
89164d0244
2 files changed
+8
-7
No files matched your search
@@ -39,7 +39,7 @@ DEFAULT_STARTTLS = False
|
||||
|
||||
# pylint: disable=no-value-for-parameter
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_RECIPIENT): vol.Email(),
|
||||
vol.Required(CONF_RECIPIENT): vol.All(cv.ensure_list, [vol.Email()]),
|
||||
vol.Optional(CONF_SERVER, default=DEFAULT_HOST): cv.string,
|
||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
||||
vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int,
|
||||
@@ -74,7 +74,7 @@ class MailNotificationService(BaseNotificationService):
|
||||
"""Implement the notification service for E-Mail messages."""
|
||||
|
||||
def __init__(self, server, port, timeout, sender, starttls, username,
|
||||
password, recipient, debug):
|
||||
password, recipients, debug):
|
||||
"""Initialize the service."""
|
||||
self._server = server
|
||||
self._port = port
|
||||
@@ -83,7 +83,7 @@ class MailNotificationService(BaseNotificationService):
|
||||
self.starttls = starttls
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.recipient = recipient
|
||||
self.recipients = recipients
|
||||
self.debug = debug
|
||||
self.tries = 2
|
||||
|
||||
@@ -139,7 +139,7 @@ class MailNotificationService(BaseNotificationService):
|
||||
msg = _build_text_msg(message)
|
||||
|
||||
msg['Subject'] = subject
|
||||
msg['To'] = self.recipient
|
||||
msg['To'] = ','.join(self.recipients)
|
||||
msg['From'] = self._sender
|
||||
msg['X-Mailer'] = 'HomeAssistant'
|
||||
msg['Date'] = email.utils.format_datetime(dt_util.now())
|
||||
@@ -152,7 +152,7 @@ class MailNotificationService(BaseNotificationService):
|
||||
mail = self.connect()
|
||||
for _ in range(self.tries):
|
||||
try:
|
||||
mail.sendmail(self._sender, self.recipient,
|
||||
mail.sendmail(self._sender, self.recipients,
|
||||
msg.as_string())
|
||||
break
|
||||
except smtplib.SMTPException:
|
||||
|
||||
Reference in new issue
Block a user