SMTP notify with Google failing often

I’m about a week into HA, so obviously still learning…

I set up a custom SMTP gmail notifier, so I could control the sender name. It worked for a couple days and then “disappeared” (existing actions using it showed it as unknown, and it no longer showed as a Notifier choice). The only hint was an error in the log that I had a 403 insufficient permissions error on the vacation setting (which I’m not using). I couldn’t find an issue, and as a last resort deleted and recreated my gmail app specific password and updated my config. Everything worked fine again for 12 hours, and now it’s failing again with the same error and “does not exist” behavior.

Here is my (redacted) configuration.yaml definition:

notify:
  - name: "Carmel GMail SMTP"
    platform: smtp
    server: "smtp.gmail.com"
    port: 587
    timeout: 15
    sender: "[email protected]"
    encryption: starttls
    username: "[email protected]"
    password: "secret"
    recipient:
      - "[email protected]"
    sender_name: "Carmel House"

My HA logs shows an error: “google_mail: Error on device update!” This includes a long traceback:

Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:737
integration: Sensor (documentation, issues)
First occurred: 12:20:05 PM (1 occurrences)
Last logged: 12:20:05 PM

google_mail: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 737, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1318, in async_device_update
    await self.async_update()
  File "/usr/src/homeassistant/homeassistant/components/google_mail/sensor.py", line 45, in async_update
    data: dict = await self.hass.async_add_executor_job(settings.execute)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.13/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.13/site-packages/googleapiclient/http.py", line 938, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://gmail.googleapis.com/gmail/v1/users/me/settings/vacation?alt=json returned "Request had insufficient authentication scopes.". Details: "[{'message': 'Insufficient Permission', 'domain': 'global', 'reason': 'insufficientPermissions'}]">

There is also a warning on googleapiclient.http: "Encountered 403 Forbidden with reason “insufficientPermissions”. Fron looking at the raw log, this appears to be from the same error above.

Hello rdlm,

Using Google for this required that you have your external_url set-up correctly and you are using a real, not self assigned, cert or it will not work correct. Nabu Casa handles this well, and you can set up your own external access multiple ways bit that is needed.

Are you sure the error belongs to the notifier? Because setting up a notifier to send mail using a (less secure) app specific password is not reliant on Google API’s. That is because app specific passwords are user for emulating oldfashioned SMTP servers for apps that are not made to support Google the official way.

The error suggests it is a sensor that is misbehaving and not a notifier service.

@Sir_Goodenough : I have //my.home-assistant.io/redirect/oauth set in Google. Can you elaborate on how Nabu Casa would help? I haven’t enabled/purchased that yet.

@Edwin_D : By “not available”, I mean that when I add an action, under “Notification” (vs “Device”), it’s not an entry I can select. As for “sensor”, I noticed that too and don’t know what it means. I’ve done NOTHING with sensors other than using built in stuff.

UPDATE: I’ve made no changes since posting the question, and when I just went back into HA to find the specific menu the notifier disappeared from, it’s back!!! But I’m 99% sure it will disappear again any time now…

Do you also have a specific Google Mail integration? The error seems to refer to it. Maybe when this is broken and trying too often, google temporarily blocks other calls?

This automation creates a notifier and sensors and IS reliant on the callback url, but it uses OAuth, not application specific passwords. If also does not require you to set up a SMTP notifier. It already creates a notifier for you. Those two ways to create notifiers are separate. I think you might have both?

@Edwin_DL Yes, I had the Google Integration installed. I was using that before I tried to move to SMTP (so I could set the sender name). I just uninstalled it and restarted HA. Sure enough, the startup permission error is gone! I’d still love to know the root cause of that, given I may have to fall back to using that if I can’t get SMTP stable.

The system log summary now shows no issue. But the SMTP notifier is once again “missing”. When I open an automation that uses it, the action shows:

I’m curious if your theory that google was blocking because of errors could be true, and if the notifier will come back – and stay back – in a little while…

I’m not that sure of my own theory. Notifiers are services. If it isn’t there that is strange. Are you sure it is being loaded? No other errors in the log, or something that might prevent it from loading? I’d expect it to load and maybe error on use, but not disappear. Unless it is no longer loaded. Maybe multiple notifier entries? They should be combined under one notifier header.

10 minutes later, and the notifier is once again available.

Looking at the raw log, I see nothing relevant. For completeness, after a restart the only WARNINGS were related to the Honeywell Total Connect Comfort add-in which needed to be re-authenticated after reboot, which is a known integration issue. No other WARNINGS nor ERRORS of any type.

1 Like

I can imagine the notifier being gone for 15 mins if it tries to send but fails… Ah no, that is seconds. Is the notifier working?

The documentation page (SMTP - Home Assistant) says that the timeout is seconds, not minutes.

Just a note that after 22 hours, it’s still stable. Evidently the GMail add-on (likely the issue with the vacation setting permissions) was making the SMTP GMail notifier unstable.

SMTP notifications with Google often fail due to strict security policies, authentication issues, or rate limits. To ensure reliable email delivery, consider using SMTPget, a dedicated SMTP service. It provides better deliverability, bypasses Google’s restrictions, and supports bulk emails with proper authentication, ensuring your notifications reach recipients without interruptions.

If your SMTP notifications with Google are failing frequently, it could be due to security settings, incorrect credentials, or Google’s restrictions. Ensure App Passwords are enabled or switch to an alternative SMTP service. For a seamless and reliable solution, DigitalAka provides expert guidance and top-notch SMTP configurations.