Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMTP component no more working #114313

Open
nicx opened this issue Mar 27, 2024 · 15 comments
Open

SMTP component no more working #114313

nicx opened this issue Mar 27, 2024 · 15 comments

Comments

@nicx
Copy link
Contributor

nicx commented Mar 27, 2024

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
Copy link

@Marcwa19197
Copy link

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
Copy link

Joe4462 commented Mar 28, 2024

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
Copy link

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
Copy link

Joe4462 commented Mar 28, 2024

The Umlaut was in the message.

  • id: '16338861470'
    alias: Mail Garage Offen
    description: ''
    trigger:
    • platform: state
      entity_id:
      • binary_sensor.garagentor_input
        to: 'on'
        from: 'off'
        condition: []
        action:
    • service: notify.garoffen
      data:
      message: Das Garagentor wurde am {{now().strftime("%d.%m.%y um %H:%M:%S")}}
      Uhr geöffnet!
      title: Garage auf:{{now().strftime(" %d.%m. - %H:%M:%S")}}
      mode: single

@Marcwa19197
Copy link

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

@jbouwh
Copy link
Contributor

jbouwh commented Mar 28, 2024

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.

@jbouwh jbouwh self-assigned this Mar 28, 2024
@Marcwa19197
Copy link

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
Copy link
Contributor

jbouwh commented Mar 28, 2024

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

@Marcwa19197
Copy link

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
Copy link
Contributor Author

nicx commented Mar 28, 2024

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
Copy link
Contributor

jbouwh commented Mar 28, 2024

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
Copy link

you mean to separate it into another .yaml file?

@jbouwh
Copy link
Contributor

jbouwh commented Mar 28, 2024

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

@jbouwh jbouwh removed their assignment Apr 1, 2024
@Stan-Gobien
Copy link

Stan-Gobien commented May 31, 2024

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants
@Marcwa19197 @jbouwh @nicx @Stan-Gobien @Joe4462 and others