From eac53b5dc3b0f21cb3d7e3e0cbba5d4fc642172b Mon Sep 17 00:00:00 2001 From: Manu Date: Sat, 29 Aug 2026 16:01:55 +0200 Subject: [PATCH] Add support for priority to SMTP integration (#180358) --- homeassistant/components/smtp/const.py | 1 + homeassistant/components/smtp/notify.py | 12 ++++++++++++ homeassistant/components/smtp/services.py | 4 ++++ homeassistant/components/smtp/services.yaml | 14 ++++++++++++++ homeassistant/components/smtp/strings.json | 13 +++++++++++++ tests/components/smtp/snapshots/test_notify.ambr | 3 ++- tests/components/smtp/test_notify.py | 4 +++- 7 files changed, 49 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/smtp/const.py b/homeassistant/components/smtp/const.py index 8a5feccbe6f7..935d077ea292 100644 --- a/homeassistant/components/smtp/const.py +++ b/homeassistant/components/smtp/const.py @@ -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" diff --git a/homeassistant/components/smtp/notify.py b/homeassistant/components/smtp/notify.py index f1a9645db849..112b4bf74d3e 100644 --- a/homeassistant/components/smtp/notify.py +++ b/homeassistant/components/smtp/notify.py @@ -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") diff --git a/homeassistant/components/smtp/services.py b/homeassistant/components/smtp/services.py index c0c019b3e79f..5b75759765e0 100644 --- a/homeassistant/components/smtp/services.py +++ b/homeassistant/components/smtp/services.py @@ -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"] + ), } ) diff --git a/homeassistant/components/smtp/services.yaml b/homeassistant/components/smtp/services.yaml index 3683d7cd09b4..32d1ad75eed7 100644 --- a/homeassistant/components/smtp/services.yaml +++ b/homeassistant/components/smtp/services.yaml @@ -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 diff --git a/homeassistant/components/smtp/strings.json b/homeassistant/components/smtp/strings.json index a8ae6784003e..0a428705cb66 100644 --- a/homeassistant/components/smtp/strings.json +++ b/homeassistant/components/smtp/strings.json @@ -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" diff --git a/tests/components/smtp/snapshots/test_notify.ambr b/tests/components/smtp/snapshots/test_notify.ambr index 9ea3311bb87c..9cfdfc7e872f 100644 --- a/tests/components/smtp/snapshots/test_notify.ambr +++ b/tests/components/smtp/snapshots/test_notify.ambr @@ -70,6 +70,7 @@ ''' MIME-Version: 1.0 Subject: Home Assistant + X-Priority: 1 (Highest) Content-Type: multipart/alternative; boundary="===============0000000000000000001==" From: Home Assistant @@ -89,7 +90,7 @@ Content-Transfer-Encoding: 7bit MIME-Version: 1.0 - + --===============0000000000000000001==-- diff --git a/tests/components/smtp/test_notify.py b/tests/components/smtp/test_notify.py index c6a1774f3955..e91a41ac7ddc 100644 --- a/tests/components/smtp/test_notify.py +++ b/tests/components/smtp/test_notify.py @@ -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: """""", + ATTR_HTML: """""", + ATTR_PRIORITY: "highest", }, blocking=True, )