Sending emails fails

Hi, I’m trying to send alert notification via email and unfortunatly it failes. I have grafana and SMTP servers running in docker containers. Docker-compose looks like this:

version: '3.9'
services:
  grafana:
    image: grafana/grafana-oss:8.2.6
    ports:
      - 3000:3000
    environment:
      - GF_ALERTING_ENABLED=false #disable dashboard alerting
      - GF_UNIFIED_ALERTING_ENABLED=true #enable alerting independent from dashboards
      - GF_SMTP_ENABLED=true
      - GF_SMTP_HOST=localhost:587
      - GF_SMTP_SKIP_VERIFY=true
    volumes:
      - grafana-storage:/var/lib/grafana

  smtp:
    image: namshi/smtp
    ports:
      - 587:587
    environment:
      - PORT=587

When I test contact point from the browser I get an info:
Failed to send test alert.: Failed to send notification to email addresses: test@myCompany.com: dial tcp 127.0.0.1:587: connect: connection refused

And in the terminal appears this:

grafana_1  | t=2022-05-04T08:51:56+0000 lvl=info msg="level=error msg=\"Missing receiver\"" logger=alerting.notifier.email
grafana_1  | t=2022-05-04T08:51:56+0000 lvl=info msg="level=error msg=\"Missing group labels\"" logger=alerting.notifier.email
grafana_1  | t=2022-05-04T08:51:56+0000 lvl=info msg="Request Completed" logger=context userId=1 orgId=1 uname=admin method=POST path=/api/alertmanager/grafana/config/api/v1/receivers/test status=207 remote_addr=192.168.1.22 time_ms=15 size=306 referer="http://localhost:8080/alerting/notifications/receivers/test-smtp/edit?alertmanager=grafana"

When my alert fires, in terminal I get:

grafana_1  | t=2022-05-04T08:50:05+0000 lvl=info msg="level=debug component=dispatcher msg=\"Received alert\" alert=alert1[17308dc][active]" logger=alertmanager org=1
grafana_1  | t=2022-05-04T08:50:05+0000 lvl=info msg="level=debug component=dispatcher aggrGroup=\"{}/{myAlert=\\\"testAlert\\\"}:{}\" msg=flushing alerts=[alert1[17308dc][active]]" logger=alertmanager org=1
grafana_1  | t=2022-05-04T08:50:05+0000 lvl=info msg="level=error component=dispatcher msg=\"Notify for alerts failed\" num_alerts=1 err=\"test-receiver/email[0]: notify retry canceled due to unrecoverable error after 1 attempts: Failed to send notification to email addresses: test@myCompany.com: dial tcp 127.0.0.1:587: connect: connection refused\"" logger=alertmanager org=1
grafana_1  | t=2022-05-04T08:45:38+0000 lvl=info msg="level=error msg=\"Missing receiver\"" logger=alerting.notifier.email
grafana_1  | t=2022-05-04T08:45:38+0000 lvl=info msg="level=error msg=\"Missing group labels\"" logger=alerting.notifier.email
grafana_1  | t=2022-05-04T08:45:38+0000 lvl=info msg="Request Completed" logger=context userId=1 orgId=1 uname=admin method=POST path=/api/alertmanager/grafana/config/api/v1/receivers/test status=207 remote_addr=192.168.1.22 time_ms=15 size=302 referer="http://localhost:8080/alerting/notifications/receivers/test-receiver/edit?alertmanager=grafana"

try increasing the verbosity of the Grafana server logs to debug and note any errors. For printing to console, set the console logs to debug as well.

Were you able to find what was wrong? I’m having the same response when testing contact point from browser. Getting response of “Missing receiver” and “Missing group labels”

1 Like

the same issue to me also
tried grafana 8.4.4 and 9
in docker

Any Solution about that??? im having the same issue

It seems that the SMTP parameters inside the docker-compose.yml are not complete.

Please add the following and then it should work.

version: "3"
services:
  grafana:
    image: grafana/grafana-oss:8.2.6
    container_name: grafana
    volumes:
    - /opt/grafana-plain/docker_volumes/grafana:/var/lib/grafana
    ports:
      - "3000:3000"
    environment:
      - 'GF_ALERTING_ENABLED=false' #disable dashboard alerting
      - 'GF_UNIFIED_ALERTING_ENABLED=true' #enable alerting independent from dashboards
      - 'GF_SMTP_ENABLED=true' #required to work
      - 'GF_SMTP_HOST=smtp-relay.gmail.com:25' #need a valid SMTP-server:port
      - 'GF_SMTP_USER=user@gmail.com' #valid user mail address
      - 'GF_SMTP_PASSWORD=mysamplePassword' #valid user password

Also, you may not need to install an SMTP server for this as it should work OR best if you have already one as your company OR home lab server then use it for SMTP.