Skip to content

Email Transport Adaptor

Transport ID Source Requirements Optional
email email.py - SMTP Integration, Google Mail Integration

Can be used for plain or HTML template emails, and handle images as attachments or embedded HTML. It will work with Home Assistant's SMTP integrations, and has its own better internal SMTP integration that can handle plain e-mail addresses as well as notify entities.

Example

Example Notification
- action: supernotify.notify
  data:
    message: "Motion detected at the front door"
    priority: high
    target:
        - homeowner@example.com

Data

Supernotify's own message_html becomes the html of the email. Anything else in data, or in extra_data on supernotify.notify, is passed on to the integration as it is, such as the SMTP integration's own html and images, or Google Mail's cc, bcc and from for a delivery with action: notify.google_mail. An html given that way wins over message_html, and any snapped image is added to the images given.

Example Notification with Pass-through Data
- action: supernotify.notify
  data:
    message: "Motion detected at the front door"
    target:
        - homeowner@example.com
    extra_data:
      images:
        - /config/www/floorplan.png

What's passed on can be pruned with the data_keys_select option, see Selection Rules.

These keys in data are Supernotify's own, and not passed on:

Key Usage
template Template to use instead of the delivery's template
footer Text added at the end of a plain email, where {e.delivery_name}, {e.notification_id}, {e.id}, {e.priority}, {e.title} and {e.message} are replaced. Not used with a template
action_url action_url for the template
action_url_title action_url_title for the template

Note

The legacy notify.supernotify action needed a data inside data for what went to the integration. That still works, with a warning in the log, but the keys belong directly in data or extra_data.

Pre-generated HTML

The notification can have a message_html supplied for html that will be used in place of the standard message for HTML emails and ignored for other notification types. This does not require templates, see the Restart Email Recipe for a simple example. In this case, HTML will automatically be tagged onto the end to include any attached images. It can be set in fixed configuration, in the data of a delivery or scenario, or as message_html in the action call.

HTML Templates

HTML templates use the standard Home Assistant Jinja2 Templating with access to entity states, additional filters etc. Templates are read once and kept, so restart Home Assistant after changing one.

Tip

HTML EMail Renders show previews of how the default template looks for different priorities.

Padding to nudge e-mail clients from reading too deeply into the e-mail for in-box summaries can be tuned with preheader_blank and preheader_length configuration in the transport options. The other useful option is strict_template to switch on or off the stricter Jinja2 template validation.

Configuration

Supernotify ships with a built in template, default.html.j2 which can be used by setting template: default.html.j2 on the delivery. This shouldn't be edited directly, since changes will get overwritten by future releases. Instead, write your own, or amended versions of default.html.j2 and put it into a custom template directory, usually inside Home Assistant's \config directory. Templates can live in this directory, or in an email subdirectory ( the top-level is for templates that could be used with any transport, and email only for this one).

Path (Re-)Configuration in Integration Page

Once a template is in that directory, set it as the template of an email delivery, and select that delivery when sending a notification:

Delivery Using a Custom Template
supernotify:
  delivery:
    back_door_email:
      transport: email
      template: back_door.html.j2
Notification Using That Delivery
- action: supernotify.notify
  data:
    title: Motion at the back door
    message: Motion has been detected at the back door
    target:
      - homeowner@example.com
    delivery: back_door_email

Template Variables

Supernotify also adds an alert variable for context of the current notification, with these values:

Attribute Description
message Notification message
title Notification title
preheader Invisible div contents at top of html used to show info below heading
priority Notification priority
envelope Delivery Envelope (complex nested object)
subheading "Home Assistant Notification", in the Home Assistant language
server Access to name,language,internal_url and external_url of this HomeAssistant server
preformatted_html HTML supplied to the notify action, for example by an Automation
action_url Action URL for mobile action
action_url_title Title for the Action URL
img Snapshot image attachment, with url and desc fields

The preheader defaults to a minimum 100 characters packed with ͏‌  to force e-mail clients not to dig into the message contents when showing a preview in the in-box.

Image Attachments

Where the image is snapped rather than being only a URL, it will be included as an attachment and an cid:XXXX URL generated to point to the attachment name.

Only files in Supernotify's media path are attached, or in a folder Home Assistant allows files to be read from: its media_dirs, www, and allowlist_external_dirs. A file from anywhere else, given in images or as a snapshot_image_path, is left out of the email with a warning, so that a notification can't be used to send out a file like secrets.yaml.

The default template escapes the message, title and links, so HTML in a message is shown as text rather than used. HTML goes in message_html, see Pre-generated HTML.

Direct Connection

By default, Supernotify uses its own SMTP connection rather than the Home Assistant one. The Home Assistant SMTP integration is moving to recipients set up one by one as notify entities, rather than any address given at the time, and its notify action has no e-mail priority.

If you already have the SMTP integration installed, Supernotify can reuse the connection details automatically if it was set up from the UI (but not if its defined in YAML). Or you can skip that altogether and use the connection section of the Supernotify transport to define it directly.

If you really want to use only the native Home Assistant integration, then override the defaults using mode: ha_smtp in the options section of a delivery or transport, see section below on configuring.

Sending through the Home Assistant SMTP Integration

With mode: ha_smtp, addresses set up as recipients in the SMTP integration are sent to with its smtp.send_message action, which has html, attachments and priority. Any other address goes by the integration's older notify action, where there is one, or else is left out with a warning.

smtp.send_message takes images as media sources rather than files, so an image Supernotify grabs is attached from one of Home Assistant's media_dirs if it was saved in one, or else as a fresh snapshot of the notification's camera. To attach the image exactly as grabbed, add Supernotify's media folder to media_dirs, as in Browse Snapshots via Home Assistant. Anything in data that smtp.send_message doesn't take, such as another integration's own keys, is left out.

Configuring

By default, the mode option is set to direct, so deliveries go through Supernotify's own SMTP capability rather than the Home Assistant notify integration. This can be set at transport level or at delivery level (if you have multiple email deliveries, such as HTML and plain).

transports:
  email:
    delivery_defaults:
      options:
        mode: direct
        sender: hass@example.com
        sender_name: Home Assistant

As for the Home Assistant SMTP integration, a sender is needed: without one, direct emails aren't sent, no default delivery is generated, and a warning is logged at startup. Without a sender_name, the email is from the home's name, as set in Home Assistant's settings. sender, sender_name and default_title can also be set in the options of a single delivery, to send that delivery's emails from a different address.

Protecting the SMTP password

Home Assistant has no secure store for credentials. The password of a connection is kept in plain text in .storage/core.config_entries, the same as for Home Assistant's own SMTP integration, and is in every backup. So:

  • Use an app password, or an account only for sending mail, rather than the password of a mailbox
  • Where the provider allows, limit it to sending
  • Encrypt backups, and take care who has access to the config folder
  • Supernotify leaves the password out of enquire_configuration, diagnostics and the archive

This avoids using the built in Home Assistant SMTP Integration, with the same functionality but without setting up each email address in Home Assistant first.

In addition to reverting to the previous simpler Home Assistant usage, it also offers:

Priority

The notification's priority is mapped to the header fields different email apps look at. Sending through the SMTP integration's smtp.send_message sets only X-Priority, which some apps, such as Outlook, ignore.

Priority Importance Priority X-Priority X-MSMail-Priority smtp.send_message
critical high urgent 1 High highest
high high urgent 2 High high
medium normal normal 3 Normal normal
low low non-urgent 4 Low low
minimum low non-urgent 5 Low lowest

Message-ID

Message-Id in email header ties back to notification ID and delivery name. (Your mail relay may override this).

Example Config

Connections default to STARTTLS over port 587, though can be changed to other ports or without encryption. This will work with Amazon SES, local mail relays etc.

connection is only used by deliveries that set mode: direct - other email deliveries on the same transport can still go via an action as normal.

transports:
  email:
    connection:
      host: smtp.local.net
      port: 587
      encryption: starttls
      username: postie
      password: blackandwhitecat
      verify_ssl: false
    delivery_defaults:
      options:
        sender: hass@local.net
        sender_name: Your Friendly Home Assistant
        default_title: Home Assistant Notification

delivery:
  direct_mail:
    transport: email
    options:
      mode: direct
    target: mailarchive@mymail.com

In addition, all of the other email options are available, such as for tuning PNG attachments or preheaders for message previews.

Reusing the Home Assistant SMTP Integration Configuration

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 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 integration, or its fork by Wheemer. Only its connection is used, not the default recipients of its account. For other ways of sending email, see 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

Initially this only preserves the original easier to use functionality of Home Assistant SMTP prior to the enforcement of pre-registering every e-mail address as an entity, and mapping envelope priority to common headers.

It is anticipated that this will also open up more features, such as modern email features like DKIM.

Discovery

Default delivery. If no email delivery is defined, an email delivery is generated automatically and fires on every notification, when either:

  • a direct connection with a sender is configured, or can be reused from the Home Assistant SMTP integration
  • the Home Assistant SMTP integration has recipients set up, or its notify action is available

To stop it being generated, switch the transport off:

transports:
  email:
    enabled: false

Reference

Home Assistant Core

Home Assistant Other

General