Triggering a custom SMTP notification - Falling at the first hurdle

That’s the same. The notify integration have to be set up properly. If it isn’t, there will be no service and so it is unknown for HA. The only thing I can think of is to check your server settings (sounding like a broken record, too :slight_smile: )
Another possibility is of course that there’s a bug in the integration refering to own SMTP servers. You could raise an issue against on Github.

Can you give me something that I can copy and paste in to see if properly formed code will run.

Is there an HA equivalent to Hello World?

The network logs say that there were no outbound SMPT requests from my HA server, and the mail sever says that there were no inbound requests, so nothing ever left HA.

I’m afraid that I don’t understand enough debug this.

IS there any documenation on this?

Try looking in your log file.

grep smtp /config/home-assistant.log

If nothing there, up the logging on notify - see the logger docs.

Oh and PLEASE stop posting pictures. Yaml is text. Logs are text.

As per my original post. I have only just started using HA, and I don’t know how to do any of that yet.

You appear to know how to type. So do it.

In the console. Or the ssh addon.

And stop posting multiple threads about the same issue.

1 Like

I want to keep the issues seperate to avoid confusing the fixes.

For example, IMAP and SMTP are separate services and the solutions will be different.

I’m sorry, but I don’t know what you are asking for so I don’t know how to provide it to you. Everything that I know how to provide is already included.

This is the error message that I’m getting in the log

Logger: homeassistant.config
Source: config.py:505
First occurred: 11:11:02 (1 occurrences)
Last logged: 11:11:02

Invalid config for [notify.smtp]: required key not provided @ data[‘recipient’]. Got None. (See /config/configuration.yaml, line 17). Please check the docs at SMTP - Home Assistant

This is the contents of my Configuration.yaml

Line 17 of my config file is where it ways “Notify:”

#Loads default set of integrations. Do not remove.

default_config:

#Load frontend themes from the themes folder

frontend:
themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
homeassistant:
allowlist_external_dirs:
- /tmp
- /share
- /share/snapshots
notify:

  • name: email_notification
    platform: smtp
    server: (my server address)
    port: (my port)
    sender: (sender email address)
    sender_name: “Home Assistant”
    starttls: true
    username: (my username)
    password: (my password)

There, see you found it. No recipient specified!

As the docs say, recipient required.

I’m following this set of instructions

Link

When I get to part 2 step 3 it tells me to select my notification from the Call service section

  1. Add the email action: To add the email action, click on the “+ Add Action” button in the actions section. Then, select “Call Service” and search for notify.email_notification from the service drop-down list. In the message and title boxes, enter the custom message and title you would like to show in the emails.

The service that I created in Part 1 is not visible.

I’ve tried re-typing it a dozen time, but it’s still not visible.

I don’t know why. I’ve soft rest and hard rebooted HA half a dozen times and the service is still not visible. Either I’ve entered something incorrectly in configuration.yaml or there’s something more fundamental going on, such as a prerequisite service not being installed.

To be absolutely clear, no smtp message ever leaves my HA serve. It’s not bouncing back due to an incorrect username or password or server address. HA is failing to send the SMTP message. It looks like it can’t even find the service to send it.

Because you didn’t complete the config by adding a recipient. Read the log. Read the docs.

I know that you’re trying to help, but could you please read the thread from the beginning. I did include a recipient the first time around. It didn’t make any difference.

The first error you had might have been different.
Add recipient, restart and re-check the logs.

I’ve added the recipient back in, rebooted the server and tried step 4 again from that link

HA core gives me two error logs

Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/connection.py:268
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 11:55:44 (1 occurrences)
Last logged: 11:55:44
[140489300863168] Error handling message: Unable to find service notify.email_notification (unknown_error)

and

Logger: homeassistant.helpers.script.websocket_api_script
Source: helpers/script.py:1783
First occurred: 11:55:44 (1 occurrences)
Last logged: 11:55:44
websocket_api script: Error executing script. Service not found for call_service at pos 1: Unable to find service notify.email_notification

Is it possible that I’m missing some prerequisite services?

This is essentially what I had in my original post.

Those are the symptoms. Look for smtp errors.

I’m afraid that I don’t know what to look for or where to look for it.

Does this mean that there is a problem with the code that I added to Configuration.YAML.

Or that there is a problem with the SMTP service running on HA

Or that there is a problem with my own SMTP server (Exchange on Windows server)

This maybe?

Home Assistant Core
Error setting up platform smtp
12:07:48 – (ERROR) Notifications

2023-11-10 12:07:48.570 ERROR (MainThread) [homeassistant.components.notify] Error setting up platform smtp

Traceback (most recent call last):

File "/usr/local/lib/python3.11/smtplib.py", line 398, in getreply

line = self.file.readline(_MAXLINE + 1)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/socket.py", line 706, in readinto

return self._sock.recv_into(b)

^^^^^^^^^^^^^^^^^^^^^^^

TimeoutError: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/usr/src/homeassistant/homeassistant/components/notify/legacy.py", line 93, in async_setup_platform

notify_service = await hass.async_add_executor_job(

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run

result = self.fn(*self.args, **self.kwargs)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/src/homeassistant/homeassistant/components/smtp/notify.py", line 100, in get_service

if mail_service.connection_is_valid():

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/src/homeassistant/homeassistant/components/smtp/notify.py", line 162, in connection_is_valid

server = self.connect()

^^^^^^^^^^^^^^

File "/usr/src/homeassistant/homeassistant/components/smtp/notify.py", line 148, in connect

mail = smtplib.SMTP(self._server, self._port, timeout=self._timeout)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/smtplib.py", line 255, in __init__

(code, msg) = self.connect(host, port)

^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/smtplib.py", line 343, in connect

(code, msg) = self.getreply()

^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/smtplib.py", line 401, in getreply

raise SMTPServerDisconnected("Connection unexpectedly closed: "

smtplib.SMTPServerDisconnected: Connection unexpectedly closed: timed out

I rebooted and got this without having attempted anything else. Just a reboot.

Well, yeah. HA just cannot connect to your SMTP server.
“Timeout” might point to a firewall issue, but we cannot tell, really

I’ve put them both inside the firewall, there should be nothing between them.

I’ve also whited the IP and all ports for HA on the SMTP for now.

Same problem.

Could it simply be a syntax error or a typo in my config?