How To Configure a Local SMTP Server to Enable Grafana Emails

grafana smtp configuration

In this tutorial, we will be going through the steps required to set up a local Simple Mail Transfer Protocol (SMTP) server on an Ubuntu system and then use that server for email notifications in Grafana. This is necessary for the “forgot password” feature to function correctly.

A little background on Grafana…

Grafana is an open-source platform for monitoring and observability. It allows you to query, visualize, alert on, and understand your metrics no matter where they are stored. It provides you with tools to turn your time-series database (TSDB) data into beautiful graphs and visualizations. Grafana supports a wide variety of data sources, including Prometheus, MySQL, and even simple JSON data. It’s widely used in various fields for functions such as real-time analytics dashboards, time series analytics, and infrastructure monitoring, among others. Grafana helps make sense of complex data, offering valuable insights for decision-making.

Before we start, it’s important to note that this setup is suitable for development environments or small networks. For larger networks and production environments, it’s recommended to use a more robust email server or service.

Grafana SMTP Server – How To Configure

Step 1: Update System Packages

Before we start with the installation, it’s always a good practice to update your system packages. Open your terminal and type:

sudo apt-get update
sudo apt-get upgrade

Step 2: Install Postfix

Postfix is a free, open-source, and widely-used SMTP server. We will use Postfix as our local SMTP server. Install it with the following command:

sudo apt-get install postfix

During the installation, a configuration window will appear.

  • For the first option, choose “Internet Site” as the general type of mail configuration.
  • For the second option, enter your server’s domain name.
See also  Choosing The Best Build Tool: Gradle vs Maven (2024)

If you need to reconfigure Postfix, you can use the following command:

sudo dpkg-reconfigure postfix

Step 3: Configure Postfix

Edit the main Postfix configuration file:

sudo nano /etc/postfix/main.cf

Make sure the following lines are either added or appropriately modified:

myhostname = your_domain.com
mydestination = $myhostname, localhost.$mydomain, localhost
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all

After you’ve made the necessary changes, save and exit the file, and restart Postfix:

sudo systemctl restart postfix

Step 4: Install and Configure Grafana

If you don’t have Grafana installed, you can install it using the following commands:

sudo apt-get install -y apt-transport-https
sudo apt-get install -y software-properties-common wget
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install grafana

Start the Grafana server:

sudo systemctl start grafana-server

Enable it to start on boot:

sudo systemctl enable grafana-server

Step 5: Configure Grafana to Use the Local SMTP Server

To set up Grafana for email alerts, open the Grafana configuration file:

sudo nano /etc/grafana/grafana.ini

Scroll down to the SMTP configuration section, uncomment (remove the preceding semicolon) the necessary lines, and edit them to match the settings of your local SMTP server:

[smtp]
enabled = true
host = localhost:25
;user =
;password =
;cert_file =
;key_file =
skip_verify = true
from_address = admin@your_domain.com
from_name = Grafana

After editing, save and exit the file, and then restart Grafana:

sudo systemctl restart grafana-server

Step 6: Test Email Notifications

Now log into Grafana (default at http://localhost:3000) with the default username (admin) and password (admin). You should change the default password when prompted.

Navigate to the Alerting menu and select Notification channels. Click on Add channel.

See also  Integrating SonarQube with Jenkins: Automate Code Quality Checks

Fill out the necessary information:

  • Name: Enter a name for the notification channel.
  • Type: Choose Email.
  • Email addresses: Enter the email addresses to send notifications to.

Click on Send Test to send a test email. If everything is configured correctly, you should receive an email from Grafana.

Troubleshooting

If the test fails or you don’t receive the email, check the logs of both Grafana and Postfix.

For Grafana, check the log using:

sudo journalctl -u grafana-server -f

For Postfix, check the log using:

sudo tail -f /var/log/mail.log

These logs should give you information about any errors that are occurring.

Congratulations! You have successfully set up a local SMTP server on your Ubuntu system and enabled email notifications in Grafana. You can now use this setup to get email notifications for any alerts you configure in Grafana.

Support us & keep this site free of annoying ads.
Shop Amazon.com or Donate with Paypal

Leave a Comment