mirror of
https://github.com/home-assistant/core.git
synced 2026-09-24 15:31:52 -05:00
Add support for priority to SMTP integration (#180358)
This commit is contained in:
@@ -11,6 +11,7 @@ ATTR_ATTACHMENTS: Final = "attachments"
|
||||
ATTR_MEDIA_SOURCE: Final = "media_source"
|
||||
ATTR_FILENAME: Final = "filename"
|
||||
ATTR_CONTENT_ID: Final = "content_id"
|
||||
ATTR_PRIORITY: Final = "priority"
|
||||
|
||||
CONF_ENCRYPTION: Final = "encryption"
|
||||
CONF_SERVER: Final = "server"
|
||||
|
||||
@@ -64,6 +64,7 @@ from .const import (
|
||||
ATTR_HTML,
|
||||
ATTR_IMAGES,
|
||||
ATTR_MEDIA_SOURCE,
|
||||
ATTR_PRIORITY,
|
||||
CONF_ENCRYPTION,
|
||||
CONF_ENTRY,
|
||||
CONF_SENDER_NAME,
|
||||
@@ -109,6 +110,14 @@ PLATFORM_SCHEMA = NOTIFY_PLATFORM_SCHEMA.extend(
|
||||
}
|
||||
)
|
||||
|
||||
MAP_X_PRIORITY = {
|
||||
"highest": "1 (Highest)",
|
||||
"high": "2 (High)",
|
||||
"normal": "3 (Normal)",
|
||||
"low": "4 (Low)",
|
||||
"lowest": "5 (Lowest)",
|
||||
}
|
||||
|
||||
|
||||
async def async_get_service(
|
||||
hass: HomeAssistant,
|
||||
@@ -225,6 +234,9 @@ class MailNotifyEntity(NotifyEntity):
|
||||
msg.set_content(message)
|
||||
msg.add_header("Subject", title or ATTR_TITLE_DEFAULT)
|
||||
|
||||
if ATTR_PRIORITY in kwargs:
|
||||
msg.add_header("X-Priority", MAP_X_PRIORITY[kwargs[ATTR_PRIORITY]])
|
||||
|
||||
if ATTR_HTML in kwargs:
|
||||
msg.add_alternative(kwargs[ATTR_HTML], subtype="html")
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ from .const import (
|
||||
ATTR_FILENAME,
|
||||
ATTR_HTML,
|
||||
ATTR_MEDIA_SOURCE,
|
||||
ATTR_PRIORITY,
|
||||
DOMAIN,
|
||||
)
|
||||
|
||||
@@ -40,6 +41,9 @@ SERVICE_SEND_MESSAGE_SCHEMA = cv.make_entity_service_schema(
|
||||
)
|
||||
],
|
||||
),
|
||||
vol.Optional(ATTR_PRIORITY): vol.In(
|
||||
["highest", "high", "normal", "low", "lowest"]
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -44,3 +44,17 @@ send_message:
|
||||
selector:
|
||||
text:
|
||||
translation_key: attachments
|
||||
priority:
|
||||
required: false
|
||||
selector:
|
||||
select:
|
||||
options:
|
||||
- highest
|
||||
- high
|
||||
- normal
|
||||
- low
|
||||
- lowest
|
||||
mode: dropdown
|
||||
translation_key: "priority"
|
||||
sort: false
|
||||
example: highest
|
||||
|
||||
@@ -183,6 +183,15 @@
|
||||
"starttls": "STARTTLS",
|
||||
"tls": "SSL/TLS"
|
||||
}
|
||||
},
|
||||
"priority": {
|
||||
"options": {
|
||||
"high": "High",
|
||||
"highest": "Highest",
|
||||
"low": "Low",
|
||||
"lowest": "Lowest",
|
||||
"normal": "Normal"
|
||||
}
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
@@ -201,6 +210,10 @@
|
||||
"description": "The plain text message body of the email notification.",
|
||||
"name": "Message"
|
||||
},
|
||||
"priority": {
|
||||
"description": "Priority of the email notification. Support for this setting varies between email clients.",
|
||||
"name": "Priority"
|
||||
},
|
||||
"title": {
|
||||
"description": "Subject for your email notification.",
|
||||
"name": "Title"
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
'''
|
||||
MIME-Version: 1.0
|
||||
Subject: Home Assistant
|
||||
X-Priority: 1 (Highest)
|
||||
Content-Type: multipart/alternative;
|
||||
boundary="===============0000000000000000001=="
|
||||
From: Home Assistant <email@example.com>
|
||||
@@ -89,7 +90,7 @@
|
||||
Content-Transfer-Encoding: 7bit
|
||||
MIME-Version: 1.0
|
||||
|
||||
<html><body><img src="cid:avatar.png"></body></html>
|
||||
<html><body><img src="https://example.com/avatar.png"></body></html>
|
||||
|
||||
--===============0000000000000000001==--
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ from homeassistant.components.smtp.const import (
|
||||
ATTR_FILENAME,
|
||||
ATTR_HTML,
|
||||
ATTR_MEDIA_SOURCE,
|
||||
ATTR_PRIORITY,
|
||||
CONF_ENTRY,
|
||||
DOMAIN,
|
||||
)
|
||||
@@ -400,7 +401,8 @@ async def test_smtp_send_message(
|
||||
{
|
||||
ATTR_ENTITY_ID: "notify.home_assistant_recipient",
|
||||
ATTR_MESSAGE: "Hello World",
|
||||
ATTR_HTML: """<html><body><img src="cid:avatar.png"></body></html>""",
|
||||
ATTR_HTML: """<html><body><img src="https://example.com/avatar.png"></body></html>""",
|
||||
ATTR_PRIORITY: "highest",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user