SMTP notify enhancements: full HTML emails and custom product_name in email headers (#7533)
* SMTP notify enhancements: HTML emails and customization options - Send full HTML emails, with or without inline attached images. - Custom `timeout`. - Custom `product_name` identifier for the `FROM` and `X-MAILER` email headers. - New HTML email test * `sender_name` instead of product_name - Change `sender_name` instead of `product_name`. - No changes in `X-Mailer` header. - `From` header as always unless you define the new `sender_name` parameter.
This commit is contained in:
1 parent
36d7fe72eb
commit
d0304198de
2 files changed
+72
-9
No files matched your search
@@ -23,7 +23,8 @@ class TestNotifySmtp(unittest.TestCase):
|
||||
self.hass = get_test_home_assistant()
|
||||
self.mailer = MockSMTP('localhost', 25, 5, 'test@test.com', 1,
|
||||
'testuser', 'testpass',
|
||||
['recip1@example.com', 'testrecip@test.com'], 0)
|
||||
['recip1@example.com', 'testrecip@test.com'],
|
||||
'HomeAssistant', 0)
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
""""Stop down everything that was started."""
|
||||
@@ -38,7 +39,7 @@ class TestNotifySmtp(unittest.TestCase):
|
||||
'Content-Transfer-Encoding: 7bit\n'
|
||||
'Subject: Home Assistant\n'
|
||||
'To: recip1@example.com,testrecip@test.com\n'
|
||||
'From: test@test.com\n'
|
||||
'From: HomeAssistant <test@test.com>\n'
|
||||
'X-Mailer: HomeAssistant\n'
|
||||
'Date: [^\n]+\n'
|
||||
'Message-Id: <[^@]+@[^>]+>\n'
|
||||
@@ -52,3 +53,24 @@ class TestNotifySmtp(unittest.TestCase):
|
||||
msg = self.mailer.send_message('Test msg',
|
||||
data={'images': ['test.jpg']})
|
||||
self.assertTrue('Content-Type: multipart/related' in msg)
|
||||
|
||||
@patch('email.utils.make_msgid', return_value='<mock@mock>')
|
||||
def test_html_email(self, mock_make_msgid):
|
||||
"""Test build of html email behavior."""
|
||||
html = '''
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head><meta charset="UTF-8"></head>
|
||||
<body>
|
||||
<div>
|
||||
<h1>Intruder alert at apartment!!</h1>
|
||||
</div>
|
||||
<div>
|
||||
<img alt="test.jpg" src="cid:test.jpg"/>
|
||||
</div>
|
||||
</body>
|
||||
</html>'''
|
||||
msg = self.mailer.send_message('Test msg',
|
||||
data={'html': html,
|
||||
'images': ['test.jpg']})
|
||||
self.assertTrue('Content-Type: multipart/related' in msg)
|
||||
Reference in new issue
Block a user