Add support for Reply-To to SMTP integration (#181040)

This commit is contained in:
Manu
2026-09-08 17:46:50 +02:00
committed by GitHub
parent 87da2fb0da
commit 11d6fb6198
7 changed files with 52 additions and 3 deletions
+10 -1
View File
@@ -49,6 +49,8 @@ from . import SmtpConfigEntry
from .const import (
CONF_ENCRYPTION,
CONF_OLD_RECIPIENT,
CONF_REPLY_TO,
CONF_REPLY_TO_NAME,
CONF_SENDER_NAME,
CONF_SERVER,
DEFAULT_ENCRYPTION,
@@ -76,7 +78,14 @@ OPTIONS_SCHEMA = vol.Schema(
)
),
vol.Coerce(int),
)
),
vol.Optional(CONF_REPLY_TO): TextSelector(
TextSelectorConfig(
type=TextSelectorType.EMAIL,
autocomplete="email",
),
),
vol.Optional(CONF_REPLY_TO_NAME): cv.string,
}
)
+3
View File
@@ -29,3 +29,6 @@ ENCRYPTION_OPTIONS: Final = ["tls", "starttls", "none"]
SUBENTRY_TYPE_RECIPIENT: Final = "recipient"
CONF_ENTRY = "entry"
CONF_OLD_RECIPIENT: Final = "old_recipient"
CONF_REPLY_TO: Final = "reply_to"
CONF_REPLY_TO_NAME: Final = "reply_to_name"
+11
View File
@@ -63,6 +63,8 @@ from .const import (
ATTR_PRIORITY,
CONF_ENCRYPTION,
CONF_ENTRY,
CONF_REPLY_TO,
CONF_REPLY_TO_NAME,
CONF_SENDER_NAME,
CONF_SERVER,
DEFAULT_DEBUG,
@@ -301,6 +303,15 @@ class MailNotifyEntity(NotifyEntity):
"To",
email.utils.formataddr((self._subentry.title, self._subentry.unique_id)),
)
if reply_to := self._entry.options.get(CONF_REPLY_TO):
msg.add_header(
"Reply-To",
email.utils.formataddr(
(self._entry.options.get(CONF_REPLY_TO_NAME), reply_to)
),
)
msg.add_header("X-Mailer", "Home Assistant")
msg.add_header("User-Agent", f"{APPLICATION_NAME}/{__version__}")
msg.add_header("Date", email.utils.format_datetime(dt_util.now()))
@@ -68,9 +68,13 @@
"sections": {
"options": {
"data": {
"reply_to": "[%key:component::smtp::options::step::init::data::reply_to%]",
"reply_to_name": "[%key:component::smtp::options::step::init::data::reply_to_name%]",
"timeout": "[%key:component::smtp::options::step::init::data::timeout%]"
},
"data_description": {
"reply_to": "[%key:component::smtp::options::step::init::data_description::reply_to%]",
"reply_to_name": "[%key:component::smtp::options::step::init::data_description::reply_to_name%]",
"timeout": "[%key:component::smtp::options::step::init::data_description::timeout%]"
},
"name": "Additional options"
@@ -149,9 +153,13 @@
"step": {
"init": {
"data": {
"reply_to": "Reply-To email address",
"reply_to_name": "Reply-To name",
"timeout": "Connection timeout"
},
"data_description": {
"reply_to": "Email address to use for recipient replies. If not specified, the sender's email address is used.",
"reply_to_name": "Display name shown as the Reply-To name.",
"timeout": "Maximum time to wait for a response from the SMTP server before the connection attempt is aborted. Defaults to 60 seconds."
}
}
+4
View File
@@ -7,6 +7,8 @@ import pytest
from homeassistant.components.smtp.const import (
CONF_ENCRYPTION,
CONF_REPLY_TO,
CONF_REPLY_TO_NAME,
CONF_SENDER_NAME,
CONF_SERVER,
DOMAIN,
@@ -130,6 +132,8 @@ def mock_config_entry() -> MockConfigEntry:
data=USER_INPUT,
options={
CONF_TIMEOUT: 1312,
CONF_REPLY_TO: "replyto@example.com",
CONF_REPLY_TO_NAME: "Reply To Name",
},
entry_id="123456789",
subentries_data=[
@@ -58,6 +58,7 @@
Subject: Home Assistant
From: Home Assistant <email@example.com>
To: Recipient <recipient@example.com>
Reply-To: Reply To Name <replyto@example.com>
X-Mailer: Home Assistant
User-Agent: HomeAssistant/2026.10.0
Date: Sat, 02 May 2026 20:09:37 -0700
@@ -76,6 +77,7 @@
boundary="===============0000000000000000001=="
From: Home Assistant <email@example.com>
To: Recipient <recipient@example.com>
Reply-To: Reply To Name <replyto@example.com>
X-Mailer: Home Assistant
User-Agent: HomeAssistant/2026.10.0
Date: Sat, 02 May 2026 20:09:37 -0700
@@ -106,6 +108,7 @@
boundary="===============0000000000000000002=="
From: Home Assistant <email@example.com>
To: Recipient <recipient@example.com>
Reply-To: Reply To Name <replyto@example.com>
X-Mailer: Home Assistant
User-Agent: HomeAssistant/2026.10.0
Date: Sat, 02 May 2026 20:09:37 -0700
@@ -150,6 +153,7 @@
Content-Type: multipart/mixed; boundary="===============0000000000000000003=="
From: Home Assistant <email@example.com>
To: Recipient <recipient@example.com>
Reply-To: Reply To Name <replyto@example.com>
X-Mailer: Home Assistant
User-Agent: HomeAssistant/2026.10.0
Date: Sat, 02 May 2026 20:09:37 -0700
@@ -208,6 +212,7 @@
Content-Type: multipart/mixed; boundary="===============0000000000000000001=="
From: Home Assistant <email@example.com>
To: Recipient <recipient@example.com>
Reply-To: Reply To Name <replyto@example.com>
X-Mailer: Home Assistant
User-Agent: HomeAssistant/2026.10.0
Date: Sat, 02 May 2026 20:09:37 -0700
@@ -238,6 +243,7 @@
Content-Type: multipart/mixed; boundary="===============0000000000000000002=="
From: Home Assistant <email@example.com>
To: Recipient <recipient@example.com>
Reply-To: Reply To Name <replyto@example.com>
X-Mailer: Home Assistant
User-Agent: HomeAssistant/2026.10.0
Date: Sat, 02 May 2026 20:09:37 -0700
+10 -2
View File
@@ -6,6 +6,8 @@ from aiosmtplib import SMTPAuthenticationError, SMTPException, SMTPTimeoutError
import pytest
from homeassistant.components.smtp.const import (
CONF_REPLY_TO,
CONF_REPLY_TO_NAME,
CONF_SENDER_NAME,
DOMAIN,
SECTION_OPTIONS,
@@ -53,7 +55,10 @@ async def test_form(
result["flow_id"],
{
**USER_INPUT,
SECTION_OPTIONS: {},
SECTION_OPTIONS: {
CONF_REPLY_TO: "replyto@example.com",
CONF_REPLY_TO_NAME: "Reply To Name",
},
},
)
await hass.async_block_till_done()
@@ -61,7 +66,10 @@ async def test_form(
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "Home Assistant"
assert result["data"] == USER_INPUT
assert result["options"] == {}
assert result["options"] == {
CONF_REPLY_TO: "replyto@example.com",
CONF_REPLY_TO_NAME: "Reply To Name",
}
assert len(mock_setup_entry.mock_calls) == 1
await hass.async_block_till_done(wait_background_tasks=True)