HTML E-mails from Zabbix

by Jakub in System Administration 18.04.2015


Zabbix is really awesome monitoring software. It comes with nice GUI and awesome alerts supports, that basically allow you to trigger anything you may want in case something happens on one of monitored servers.

When we migrated from Nagios to Zabbix, first thing that we wanted to setup were SMS notifications and e-mail notifications. Default options of Zabbix were not enough. It supports SMS notifications by default, but using GSM modem and we don't have and don't want any GSM modem connected to our server, so we have setup SMS using clickatell API (I will probably explain in future).

We had similar issue with e-mails, we wanted to use mailgun awesome service, but by default it doesn't support authentication that we need to have for mailgun:zabbix email media

Also, it doesn't support HTML emails and notifications look ugly.So, using some help from forum (I can't find link now, will attach it as soon as I find it) and few tune ups, we've managed to create notifications like we wanted:zabbix formatted email


We assume that:

  • You have configured Zabbix instance with agents.
  • You have access to console on zabbix server and root access
  • You use Debian. If you use RedHat or CentOS, you may need to find proper package names and use yum instead of aptitude.

Stage 1: Console

1: Install sendEmail

$ aptitude install sendemail

2: Go to console, check where alert scripts are stored and go there.

$ cat /etc/zabbix/zabbix_server.conf | grep AlertScriptsPath=# 
$ cd /etc/zabbix/alert.d/

3: Create new script

$ nano

4: Paste there following script, fill it with proper SMTP credentials. Note: tls=no option was the one that made it working with mailgun.

export [email protected]
export zabbixemailto="$1"
export zabbixsubject="$2"
export zabbixbody="$3"
export smtpserver=SMTP_HOST
export smtplogin=SMTP_LOGIN
export smtppass=SMTP_PASSWORD
/usr/bin/sendEmail -f $smtpemailfrom -t $zabbixemailto -u $zabbixsubject \-m $zabbixbody -s $smtpserver:25 -xu $smtplogin -xp $smtppass -o tls=no \-o message-content-type=html

5: Set up permissions and test

$ chmod 755
$ sudo -u zabbix bash
$ ./ [email protected] 'zabbix test message' 'some html message'

Stage 2 - Zabbix PHP GUI

  1. Login to GUI and go to Administration -> Media Types and click Email.
  2. Change type to Script, put into script name and Save.
  3. Go to Configuration -> Actions and click Create action.
  4. Fill the fields in Action tab. Note: you may use HTML here! Here is how we did this:
  5. Change conditions in Conditions tab if required - by default email will be sent for all problems.
  6. Go to Operations tab, click New. Add user group or user, select Send only to to Email, click Add and then click Save.7. Go to Administration -> Users, click on user that should get emails.8. Go to Media tab, click Add, select Type Email, put proper e-mail to Send to field and make sure that Status is Enabled.


After doing all steps above you should start getting nicely formatted notifications emails - no need to wait for!

If you don't get it and console tests went fine - check that zabbix user has Read access to given servers or check SMTP Servers logs.

linux zabbix


Viamage Avatar