Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

[Appliance Auto Notify](https://appliance-autonotify.rhizomatics.org.uk) will discover your dishwashers and ovens (limited to HomeConnect enabled in first releases) and power monitors, and set up progress bar style live activities automatically on phones. No automations, no actions.

[Camera Auto Notify](https://camera-autonotify.rhizomatics.org.uk/) automatic notifications from security cameras, so far supporting Frigate and ANPR2MQTT. No blueprints, no automations, no YAML.
[Camera Auto Notify](https://camera-autonotify.rhizomatics.org.uk/) automatic notifications from security cameras, so far supporting Frigate, OpenALPR and ANPR2MQTT. No blueprints, no automations, no YAML.

# v2.19.1

## ✨ Enhancements
- *Email*: where Home Assistant's SMTP integration isn't set up, a direct SMTP email uses the connection of the custom [Email Notifier](https://github.com/microteq/email_notifier) integration, or of [Wheemer's fork](https://github.com/Wheemer/email_notifier), if set up from the UI. Only the connection, sender and sender name are used, not the default recipients of its account, see [Reusing the Home Assistant SMTP Integration Configuration](https://supernotify.rhizomatics.org.uk/latest/transports/email/#reusing-the-home-assistant-smtp-integration-configuration)

## 📝 Other changes
- *Documentation*: a checklist of [what to look for in an email integration](https://supernotify.rhizomatics.org.uk/latest/transports/email/#what-to-look-for-in-an-email-integration)

# v2.19.0

Expand Down
2 changes: 1 addition & 1 deletion custom_components/supernotify/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
"aiofiles>=24.1.0"
],
"single_config_entry": true,
"version": "2.19.0"
"version": "2.19.1"
}
16 changes: 11 additions & 5 deletions custom_components/supernotify/transports/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
# connection is configured here. "server" is smtp-specific; the rest match generic
# homeassistant.const keys already imported above.
HA_SMTP_DOMAIN = "smtp"
# the custom Email Notifier integration (microteq/email_notifier and its forks), a UI-configured
# SMTP alternative whose config entry uses the same keys as Home Assistant's smtp integration
EMAIL_NOTIFIER_DOMAIN = "email_notifier"
SMTP_SEND_MESSAGE = "send_message"
# Duplicates of the constants in `homeassistant.components.smtp.const`, to be kept aligned with it,
# since importing from there loads the smtp integration and so needs its `aiosmtplib` requirement,
Expand Down Expand Up @@ -252,12 +255,15 @@ def __init__(self, context: Context, transport_config: ConfigType | None = None)

def _reuse_ha_smtp_connection(self) -> None:
"""No direct SMTP connection configured here; fall back to a configured HA smtp
integration entry, if any."""
entry_data = self.hass_api.find_config_entry_data(HA_SMTP_DOMAIN)
if not entry_data:
_LOGGER.debug("SUPERNOTIFY No home assistant official smtp configuration to reuse")
integration entry, if any, or else a custom Email Notifier one."""
for domain in (HA_SMTP_DOMAIN, EMAIL_NOTIFIER_DOMAIN):
entry_data = self.hass_api.find_config_entry_data(domain)
if entry_data:
break
else:
_LOGGER.debug("SUPERNOTIFY No smtp or email_notifier configuration to reuse")
return
_LOGGER.info("SUPERNOTIFY Email transport reusing connection from HA smtp integration for direct SMTP sends")
_LOGGER.info("SUPERNOTIFY Email transport reusing connection from %s integration for direct SMTP sends", domain)
self.host = entry_data.get(CONF_SERVER)
self.port = entry_data.get(CONF_PORT, self.port)
self.encryption = entry_data.get(CONF_ENCRYPTION, self.encryption)
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration/email.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Amazon have more help on how to get their SMTP set up at [Set up email sending w
## Other Email Options

* [ha-smtp](https://github.com/manjotsc/ha-smtp) - custom integration for SMTP that doesn't need YAML config
* [email-notifier](https://github.com/microteq/email_notifier) - Another UI-configured alternative SMTP integration
* [email-notifier](https://github.com/microteq/email_notifier) - Another UI-configured alternative SMTP integration, whose `email_notifier.send` action can send to any address. [Wheemer's fork](https://github.com/Wheemer/email_notifier) adds SMTP relays without a login. Supernotify can reuse its connection, see [Reusing the Home Assistant SMTP Integration Configuration](../transports/email.md#reusing-the-home-assistant-smtp-integration-configuration)
* [MS365 Mail for Home Assistant](https://rogerselwyn.github.io/MS365-Mail/) - Microsoft based e-mail sending
* Self Hosting
* [Mail-in-a-Box](https://mailinabox.email) - Run on your own server, including receiving mail, running own webmail service
Expand Down
24 changes: 24 additions & 0 deletions docs/transports/email.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,30 @@ In addition, all of the other `email` options are available, such as for tuning

If no `connection` block is configured, this transport falls back to the connection details (server, port, encryption, username, password, `verify_ssl`, sender, sender name) from a configured [SMTP Integration](https://www.home-assistant.io/integrations/smtp/) config entry, so you don't have to duplicate credentials. This only applies to ConfigFlow (UI) based SMTP integration setups, not the legacy YAML `platform: smtp` style. Omit `connection` entirely to use this.

Where the Home Assistant SMTP integration isn't set up, the connection is taken in the same way from the
custom [Email Notifier](https://github.com/microteq/email_notifier) integration, or its fork by
[Wheemer](https://github.com/Wheemer/email_notifier). Only its connection is used, not the default recipients of its account.
For other ways of sending email, see [Other Email Options](../configuration/email.md#other-email-options).

### What to Look For in an Email Integration

Before relying on a custom email integration, check that:

- **Sending doesn't hold up Home Assistant.** Connecting to the mail server, sending, testing the connection
during setup, and reading attachment files should all happen in the background. If they don't, Home Assistant
pauses while an email goes out, and the log has `Detected blocking call` warnings.
- **Each account's settings are kept apart.** With more than one account, two emails sent at the same time
should never mix up which login, sender or recipients are used.
- **A failed send is reported as an error.** If an email can't be sent, the action should fail, so that the
automation, or Supernotify's delivery record, shows it, rather than the failure appearing only in the log.
- **Home Assistant starts without the mail server.** If the mail server is down, startup shouldn't wait on it
or fail.
- **Attachments are limited to allowed folders.** Local files should only come from folders Home Assistant
allows, such as `allowlist_external_dirs`. Files downloaded from a URL should use Home Assistant's shared web
session, with a timeout.
- **Entity IDs don't change.** An account's entity ID shouldn't depend on the order in which accounts load.
- **It's maintained.** Look for tests, Home Assistant's `hassfest` validation, and recent fixes to reported issues.


### Roadmap

Expand Down
40 changes: 40 additions & 0 deletions tests/components/supernotify/transports/test_transport_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,46 @@ def test_reuses_ha_smtp_connection_when_not_configured() -> None:
assert uut.validate_action(None) is True


def test_reuses_email_notifier_connection_when_no_ha_smtp() -> None:
context = Mock(custom_template_path=None)
# as saved by the Wheemer fork, which leaves out blank credentials for a local relay
email_notifier_data = {
"server": "relay.example.com",
CONF_PORT: 25,
CONF_ENCRYPTION: "none",
"recipients": "someone@example.com",
CONF_SENDER: "notifier@example.com",
OPTION_SENDER_NAME: "Email Notifier",
"timeout": 15,
}
context.hass_api.find_config_entry_data.side_effect = lambda domain: (
email_notifier_data if domain == "email_notifier" else None
)
uut = EmailTransport(context, {})

assert [c.args[0] for c in context.hass_api.find_config_entry_data.call_args_list] == ["smtp", "email_notifier"]
assert uut.host == "relay.example.com"
assert uut.port == 25
assert uut.encryption == "none"
assert uut.username is None
assert uut.password is None
assert uut.sender == "notifier@example.com"
assert uut.sender_name == "Email Notifier"
assert uut.validate_action(None) is True


def test_ha_smtp_connection_preferred_over_email_notifier() -> None:
context = Mock(custom_template_path=None)
context.hass_api.find_config_entry_data.side_effect = lambda domain: {
"server": f"{domain}.example.com",
CONF_SENDER: "ha@example.com",
}
uut = EmailTransport(context, {})

context.hass_api.find_config_entry_data.assert_called_once_with("smtp")
assert uut.host == "smtp.example.com"


def test_existing_connection_not_overridden_by_ha_smtp() -> None:
context = Mock(custom_template_path=None)
uut = EmailTransport(context, SMTP_TRANSPORT_CONFIG)
Expand Down
Loading