Setup SMTP with Gmail

Hi all,

I’m trying to setup alerting by having Grafana send emails through the Gmail SMTP.
I run Grafana in docker so I setup SMTP using in a dockerfile:

  - GF_SMTP_ENABLED=true
  - GF_SMTP_HOST=smtp.gmail.com:587
  - GF_SMTP_USER=My_account@gmail.com
  - GF_SMTP_PASSWORD="""My_Password"""
  - GF_SMTP_SKIP_VERIFY=false
  - GF_SMTP_FROM_NAME=grafana
  - GF_SMTP_FROM_ADDRESS=My_account@gmail.com

I’m getting the following error:
535 5.7.8 Username and Password not accepted

I have tried many solutions found in these forums but none seems to work.
I know Gmail use to have a setting " Less secure app access" but you can’t use it anymore.
Is it still viable to use Gmail in Grafana without this setting?
If it is, how?

I believe you now have to use what Google calls “App Passwords”. And to use them you need to enable 2-factor authentication on your Google account. See here:

1 Like

This is correct.
It works now.
Thanks.

Hello everyone,

getting a bit crazy about that one, not sure I’m missing an obvious thing, but since I’m getting close to giving up, time to call for help :slight_smile:

I have a Home assistant running like a charm on RaspPi 4, latest Core, Supervisor, OS, FE versions, installed the grafana add-on over the week-end to get up to speed on « Monitoring & Observability », starting by monitoring my Internet connection.

InfluxDB created, added as a data source to Grafana, first grafana dashboard looks pretty cool (although very basic), setting up thresholds, happy bunny, until I want to send alerts. I’m not going to use PagerDuty for home appliance (that would be over the top), so email alert will do, if only it would work :frowning:

This is the issue:

logger=ngalert.sender.router rule_uid=f21331a5-c7f6-49f0-9ca4-6adfae7d742f org_id=1 t=2023-11-22T20:45:00.280128903+01:00 level=info msg="Sending alerts to local notifier" count=1
logger=ngalert.notifier.alertmanager 1=(MISSING) t=2023-11-22T20:45:00.606234641+01:00 level=error component=alertmanager orgID=1 component=dispatcher msg="Notify for alerts failed" num_alerts=1 err="grafana-alert-email/email[0]: notify retry canceled due to unrecoverable error after 1 attempts: failed to send notification to email addresses: mymaill@gmail.com: EOF"

My SMTP config looks like that (home assistant config style)

- name: GF_SMTP_ENABLED
  value: "true"
- name: GF_SMTP_HOST
  value: smtp.gmail.com:587
- name: GF_SMTP_USER
  value: mymail@gmail.com
- name: GF_SMTP_PASSWORD
  value: xxxxxxxxxxxxxx
- name: GF_SMTP_SKIP_VERIFY
  value: "false"
- name: GF_SMTP_FROM_NAME
  value: grafana
- name: GF_SMTP_FROM_ADDRESS
  value: mymail@gmail.com

I am using the so-called app password from Google Mail and I have confirmed that it works as I have been able to generate emails with other apps (InfluxDB for example). Any idea what the issue could be?

Many thanks in advance!

Rom