home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
69.74k stars 28.91k forks source link

SMTP component no more working #114313

Open nicx opened 3 months ago

nicx commented 3 months ago

The problem

The SMTP component is no more working since some time. Until a few weeks ago, it worked for years. after restarting home assistant, it may sometimes work, but most of the time I get an error message in the log file (see below). Unfortunately I do not now when exactly the problem began.

I did not do any changes on the mailserver side. It is a simple relay exim mailserver. All other mail clients using that mailserver are working without problems for years, too.

What version of Home Assistant Core has the issue?

2024.3.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

SMTP

Link to integration documentation on our website

https://www.home-assistant.io/integrations/smtp/

Diagnostics information

No response

Example YAML snippet

notify:
  - name: mail_***
    platform: smtp
    server: 192.168.0.1
    port: 25
    encryption: none
    timeout: 15
    sender: "***"
    sender_name: "Home Assistant"
    recipient: "***"

Anything in the logs that might be useful for us?

2024-03-27 00:05:19.610 ERROR (MainThread) [homeassistant.components.notify] Error setting up platform smtp
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/notify/legacy.py", line 94, in async_setup_platform
    notify_service = await hass.async_add_executor_job(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/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 102, in get_service
    if mail_service.connection_is_valid():
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/smtp/notify.py", line 164, in connection_is_valid
    server = self.connect()
             ^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/smtp/notify.py", line 152, in connect
    mail.ehlo_or_helo_if_needed()
  File "/usr/local/lib/python3.12/smtplib.py", line 611, in ehlo_or_helo_if_needed
    if not (200 <= self.ehlo()[0] <= 299):
                   ^^^^^^^^^^^
  File "/usr/local/lib/python3.12/smtplib.py", line 452, in ehlo
    (code, msg) = self.getreply()
                  ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/smtplib.py", line 405, in getreply
    raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed

Additional information

No response

home-assistant[bot] commented 3 months ago

smtp documentation smtp source

Marcwa19197 commented 3 months ago

Got the same issue. SMTP Integration seems to be very unstable. A config-reload brings the service back to action....

Also i guess if the Network / Internet connection is broken for a while, Notify-SMTP-Integration is lost till HA Configuration is reloaded in Developer-Tools.

My Config:

notify:
  - name: "apple_mail_notification_customdomain_tld"
    platform: smtp
    sender: "notification@customdomain.tld"
    recipient: "blahblah@icloud.com"
    server: "smtp.mail.me.com"
    port: 587
    timeout: 5
    username: "blahblah@icloud.com"
    password: 'blahblah-my-app-specifiy-password'
    encryption: "starttls"
    sender_name: "HomeAssistant"
    verify_ssl: false
    debug: true
Joe4462 commented 3 months ago

I have 2 almost identical "Send Mail" services. Since this week(maybe Core 2024.3.3?) only one of them ist working. I experimented a little and found the reason: The not-working Mail has an "Umlaut" "ö" in the Text. Deleted the "ö": SMTP is working, changed it back: not working. Maybe that helps a little

Marcwa19197 commented 3 months ago

Oh okay, but you mean within the config or within for example the message or subject of the mail which should be sent? Im using a HTML-Formatted Mail content...

Joe4462 commented 3 months ago

The Umlaut was in the message.

Marcwa19197 commented 3 months ago

Okay, yeah, checked all my Mail Templates but there are no Umlauts used... So really strange.

jbouwh commented 3 months ago

Did a test at my production instance running HA OS. The SMTP notification service just works fine for me. What mail provider are you having issues with? If it is a public provider I could may be do a test. No credentials needed.

Marcwa19197 commented 3 months ago

The issue is only happening sometimes (on my end). So i had the issue twice till now: "Service is not available" after a config-reload the automation worked again... im not sure when this is happening.

Im using my iCloud+ Account with Custom-Domain for sending the Mails.

jbouwh commented 3 months ago

can you share the host name of the SMTP server you are using, only if it is a public server?

Marcwa19197 commented 3 months ago

its not a public one..

notify:
  - name: "apple_mail_notification_customdomain_tld"
    platform: smtp
    sender: "notification@customdomain.tld"
    recipient: "blahblah@icloud.com"
    server: "smtp.mail.me.com"
    port: 587
    timeout: 5
    username: "blahblah@icloud.com"
    password: 'blahblah-my-app-specifiy-password'
    encryption: "starttls"
    sender_name: "HomeAssistant"
    verify_ssl: false
    debug: true
nicx commented 3 months ago

the issue is not permanent here, too. sometimes it works after a reboot, sometimes not. sometimes the servic crashes even it was running after some hours. I recognize the crash becuse i get a message that my automation cannot fint the notify service anymore.

in my case i am using a local exim mailserver (as a relay) without authentification. as already said, thos worked for years without any problems. there is no error log or any other log on the exim side. its just the ha smtp integration crashing :(

jbouwh commented 3 months ago

I think the smtp integration should be moved to use config flow. This enables to make the entry startup more robust. But the logging is not handled in an optimal way either.

Marcwa19197 commented 3 months ago

you mean to separate it into another .yaml file?

jbouwh commented 3 months ago

No, but use a config entry, it will also allow it to be set up from the ui

Stan-Gobien commented 1 month ago

I think I have the same issue. `Logger: homeassistant.components.notify Source: components/notify/legacy.py:104 integration: Notifications (documentation, issues) First occurred: 23:06:52 (3 occurrences) Last logged: 23:07:27

Error setting up platform smtp Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/notify/legacy.py", line 104, in async_setup_platform notify_service = await hass.async_add_executor_job( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TimeoutError: timed out`

EDIT: My issue was indeed a time-out connection, because HA was trying to use the wrong interface (multi-homed HA).