mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
This commit is contained in:
parent
efdf51b542
commit
c89e6ec915
@ -9,6 +9,7 @@ import smtplib
|
|||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from email.mime.image import MIMEImage
|
from email.mime.image import MIMEImage
|
||||||
|
import email.utils
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ from homeassistant.components.notify import (
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_USERNAME, CONF_PASSWORD, CONF_PORT, CONF_SENDER, CONF_RECIPIENT)
|
CONF_USERNAME, CONF_PASSWORD, CONF_PORT, CONF_SENDER, CONF_RECIPIENT)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -134,6 +136,8 @@ class MailNotificationService(BaseNotificationService):
|
|||||||
msg['To'] = self.recipient
|
msg['To'] = self.recipient
|
||||||
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['Message-Id'] = email.utils.make_msgid()
|
||||||
|
|
||||||
return self._send_email(msg)
|
return self._send_email(msg)
|
||||||
|
|
||||||
|
@ -34,16 +34,18 @@ class TestNotifySmtp(unittest.TestCase):
|
|||||||
def test_text_email(self):
|
def test_text_email(self):
|
||||||
"""Test build of default text email behavior."""
|
"""Test build of default text email behavior."""
|
||||||
msg = self.mailer.send_message('Test msg')
|
msg = self.mailer.send_message('Test msg')
|
||||||
expected = ('Content-Type: text/plain; charset="us-ascii"\n'
|
expected = ('^Content-Type: text/plain; charset="us-ascii"\n'
|
||||||
'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: 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'
|
||||||
|
'Message-Id: <[^@]+@[^>]+>\n'
|
||||||
'\n'
|
'\n'
|
||||||
'Test msg')
|
'Test msg$')
|
||||||
self.assertEqual(msg, expected)
|
self.assertRegex(msg, expected)
|
||||||
|
|
||||||
def test_mixed_email(self):
|
def test_mixed_email(self):
|
||||||
"""Test build of mixed text email behavior."""
|
"""Test build of mixed text email behavior."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user