mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Allow multiple recipients for SMTP notify (#7319)
The existing (singular) configuration keyword is kept for compatibility.
This commit is contained in:
parent
0298522fd5
commit
89164d0244
@ -39,7 +39,7 @@ DEFAULT_STARTTLS = False
|
|||||||
|
|
||||||
# pylint: disable=no-value-for-parameter
|
# pylint: disable=no-value-for-parameter
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
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_SERVER, default=DEFAULT_HOST): cv.string,
|
||||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
||||||
vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int,
|
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."""
|
"""Implement the notification service for E-Mail messages."""
|
||||||
|
|
||||||
def __init__(self, server, port, timeout, sender, starttls, username,
|
def __init__(self, server, port, timeout, sender, starttls, username,
|
||||||
password, recipient, debug):
|
password, recipients, debug):
|
||||||
"""Initialize the service."""
|
"""Initialize the service."""
|
||||||
self._server = server
|
self._server = server
|
||||||
self._port = port
|
self._port = port
|
||||||
@ -83,7 +83,7 @@ class MailNotificationService(BaseNotificationService):
|
|||||||
self.starttls = starttls
|
self.starttls = starttls
|
||||||
self.username = username
|
self.username = username
|
||||||
self.password = password
|
self.password = password
|
||||||
self.recipient = recipient
|
self.recipients = recipients
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.tries = 2
|
self.tries = 2
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ class MailNotificationService(BaseNotificationService):
|
|||||||
msg = _build_text_msg(message)
|
msg = _build_text_msg(message)
|
||||||
|
|
||||||
msg['Subject'] = subject
|
msg['Subject'] = subject
|
||||||
msg['To'] = self.recipient
|
msg['To'] = ','.join(self.recipients)
|
||||||
msg['From'] = self._sender
|
msg['From'] = self._sender
|
||||||
msg['X-Mailer'] = 'HomeAssistant'
|
msg['X-Mailer'] = 'HomeAssistant'
|
||||||
msg['Date'] = email.utils.format_datetime(dt_util.now())
|
msg['Date'] = email.utils.format_datetime(dt_util.now())
|
||||||
@ -152,7 +152,7 @@ class MailNotificationService(BaseNotificationService):
|
|||||||
mail = self.connect()
|
mail = self.connect()
|
||||||
for _ in range(self.tries):
|
for _ in range(self.tries):
|
||||||
try:
|
try:
|
||||||
mail.sendmail(self._sender, self.recipient,
|
mail.sendmail(self._sender, self.recipients,
|
||||||
msg.as_string())
|
msg.as_string())
|
||||||
break
|
break
|
||||||
except smtplib.SMTPException:
|
except smtplib.SMTPException:
|
||||||
|
@ -22,7 +22,8 @@ class TestNotifySmtp(unittest.TestCase):
|
|||||||
"""Setup things to be run when tests are started."""
|
"""Setup things to be run when tests are started."""
|
||||||
self.hass = get_test_home_assistant()
|
self.hass = get_test_home_assistant()
|
||||||
self.mailer = MockSMTP('localhost', 25, 5, 'test@test.com', 1,
|
self.mailer = MockSMTP('localhost', 25, 5, 'test@test.com', 1,
|
||||||
'testuser', 'testpass', 'testrecip@test.com', 0)
|
'testuser', 'testpass',
|
||||||
|
['recip1@example.com', 'testrecip@test.com'], 0)
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
""""Stop down everything that was started."""
|
""""Stop down everything that was started."""
|
||||||
@ -36,7 +37,7 @@ class TestNotifySmtp(unittest.TestCase):
|
|||||||
'MIME-Version: 1.0\n'
|
'MIME-Version: 1.0\n'
|
||||||
'Content-Transfer-Encoding: 7bit\n'
|
'Content-Transfer-Encoding: 7bit\n'
|
||||||
'Subject: Home Assistant\n'
|
'Subject: Home Assistant\n'
|
||||||
'To: testrecip@test.com\n'
|
'To: recip1@example.com,testrecip@test.com\n'
|
||||||
'From: test@test.com\n'
|
'From: test@test.com\n'
|
||||||
'X-Mailer: HomeAssistant\n'
|
'X-Mailer: HomeAssistant\n'
|
||||||
'Date: [^\n]+\n'
|
'Date: [^\n]+\n'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user