SMTP not working and SMTP integration not available

Make sure to generate an app password if you are using Gmail and have MFA turned on.
https://support.google.com/mail/answer/185833?hl=en-GB

Just want to mention to anybody else who finds this thread.

I’m running an smtp server on my network that I’m pointing home assistant at. I had it working, then it stopped working at some point recently. The notify service would appear only if I put in an invalid IP address. I had to set verify_ssl to false in my configuration. I’m guessing a recent update changed the default value.

3 Likes

THANK YOU DAVID!!! THIS WAS IT!!! Created an account just to tell you adding that line completely fixed my issue. What a pita!

David, thanks for that update. Some recent update (or maybe in the last couple of years) broke my email notifications, and the verify_ssl: false addition to my smtp config fixed the sending issue. In the logs it would show that the notify.email service wasn’t available, and your line fixed the issue.

Thanks again!

P.S. I am running my own local email server, which might have something to do with why it’s now required. I use self signed ssl certs.

I have the same problem and errors:

2022-11-15 21:05:09.983 ERROR (MainThread) [homeassistant.components.notify] Error setting up platform smtp
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/smtplib.py", line 398, in getreply
    line = self.file.readline(_MAXLINE + 1)
  File "/usr/local/lib/python3.10/socket.py", line 705, 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 92, in async_setup_platform
    notify_service = await hass.async_add_executor_job(
  File "/usr/local/lib/python3.10/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 92, in get_service
    if mail_service.connection_is_valid():
  File "/usr/src/homeassistant/homeassistant/components/smtp/notify.py", line 154, in connection_is_valid
    server = self.connect()
  File "/usr/src/homeassistant/homeassistant/components/smtp/notify.py", line 140, in connect
    mail = smtplib.SMTP(self._server, self._port, timeout=self._timeout)
  File "/usr/local/lib/python3.10/smtplib.py", line 255, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/local/lib/python3.10/smtplib.py", line 343, in connect
    (code, msg) = self.getreply()
  File "/usr/local/lib/python3.10/smtplib.py", line 401, in getreply
    raise SMTPServerDisconnected("Connection unexpectedly closed: "
smtplib.SMTPServerDisconnected: Connection unexpectedly closed: timed out

I also wanted to notify anyone having problems with SMTP not working to try setting encryption: none in case you are using an SMTP server without encryption (e.g. an old fashioned SMTP server listening on port 25 with no starttls).
This wasn’t mentioned in the documentation and I thought that the encryption line would only be needed if using starttls, but after tweaking for some time I tried setting encryption: none and that’s when it started working.

Edit: When actually reading through the documentation I found that my comment above, regarding the documentation, is false. The encryption variable is indeed documented in the documentation and it clearly states it is an optional variable which defaults to starttls. This explains why I had to explicitly declare the variable as none in the config. I’ll leave this comment here, however, in case someone else runs into this same problem.

The information in this thread is helpful. Unfortunately, I am still unable to get this to work at all.

Although I have followed the samples in the notes above, when I look at all of the services on my HA instance, all I see is ‘notify.notify’. It seems to ignore the name.

This is what I have in my configuration.yaml:

notify:

I have tried using tis instead of starttls, I have tried using port 465 instead of 587, I have removed the timeout, and also tried using [email protected] (for my mobile number) but nothing seems to show the service ‘RickCell’ or ‘notify.rickcell’. Checking the configuration beforehand always shows no problems.

I do have MFA configured for my SMTP email address, but (theoretically) that shouldn’t matter.

Any thoughts? Thanks in advance.

Did you set up an app password? You don’t use your normal Gmail password.
I forget how to do this but you should be able to find out how via google.

Thanks - great question. Turns out that I do ‘not’ use 2FA on this particular email account (although I may turn it on anyway, just for good security), so there is no option to create an app-specific account. Had I turned on 2FA, then your suggestion would have probably been necessary in order for it to work.

Unfortunately, even if that was the issue (and I added an app-specific password), it still doesn’t resolve the problem of HA not ‘seeing’ the ‘notify.rickcell’ service (right now, it only shows ‘notify.notify’).

Thanks for responding.

Here is a known good Google config that will create a service called notify.gmail. I can’t tell for sure because the post editor modified your YAML but it looks to me like the name in your YAML is too far indented:

   notify:
     - name: gmail
       platform: smtp
       server: "smtp.gmail.com"
       port: 587
       sender: "[email protected]"
       encryption: starttls
       username: "[email protected]"
       password: !secret google_app_password
       recipient:
         - "[email protected]"
         - "[email protected]"

Also note that the Google password in my secrets file includes its spaces and is NOT enclosed in quotes

Thanks, landolfi, for the help. I do appreciate it.

I modified my notify config to:

  • add double-quotes where you showed them
  • Modified my recipient look like yours (although I only have one recipient at this time)
  • removed my sender-name entry (for now)

However, it didn’t seem to make a difference.When I go to Developer tools then select Services, and click on the drop-down list of all services, I see the notify.notify service, but not my expected ‘notify.rick_cell’ service. Very frustrating…

Well, due to some else’s help, the problem is that Google wouldn’t accept my login credentials, even though I provided the correct email address and password.

The error message I got is:

smtsmtplib.SMTPAuthenticationError: (534, b’5.7.9 Application-specific password required.

However, when I logged into that Google account and opened the security settings, there is no option for app-specific passwords (like I have used with other email domains). Google is moving towards passkeys, but I can’t figure out how to create a passkey on my Mac and transfer that information to the HA configuration.yaml file.

Does anyone have any thoughts on how to get around this? Thanks.