Use The Email Media Type And Create A Send Only SMTP Server
It is important to get email alerts when a trigger happens in Zabbix. If you don't already have a SMTP server for sending emails, you can also install a Send Only server on the Zabbix Server itself.
In this video I show you how to create your own minimal SMTP server on the Zabbix server itself specifically for the purpose of sending emails. If you already have a SMTP server setup somewhere else that you can use, then you can use that instead.
To install Postfix on your Zabbix server
sudo apt install mailutils
sudo yum install postfix
On Ubuntu, a postfix config screen should appear,
select 'internet site'
enter the mail servers name, it should be the url you've already configured in your domain name provider.
For example. I pre set up an A name record for zabbix.seanwasere.com and it now points to the IP Address of the this new Zabbix Server.
Try a ping to ensure your domain resolves to your zabbix servers IP.
Of course, replace your-domain.tld with your actual domain. eg, zabbix.seanwasere.com
Then configure postfix by calling
sudo nano /etc/postfix/main.cf
scroll to the bottom, and set
inet_interfaces = loopback-only inet_protocols = ipv4
If you didn't get the configuration page when installing postfix (Centos usually), also ensure you have your domain name added to the main.cf.
myhostname = zabbix.your-domain.tld mydomain = your-domain.tld #<---note that the subdomain part is removed here mydestination = $myhostname, localhost.localdomain, localhost
sudo systemctl restart postfix
Try sending an email from the command line,
echo "This is the body" | mail -s "This is the subject" -a "FROM:email@example.com" your@email-address
echo -e "Subject: This is the subject\n\nThis is the body\n" | sendmail -f firstname.lastname@example.org -v your@email-address
Minimal Email Media Type Settings in Zabbix UI
The most significant thing you can do, is to make sure that reverse DNS lookups work for your chosen domain name.
Eg, using the host command on a different servers, query your zabbix server by its domain name.
> zabbix.your-domain.tld has address 111.222.333.444
Then do the reverse look up
> 444.333.222.111.in-addr.arpa domain name pointer zabbix.your-domain.tld.
If the reverse dns lookup works for your domain, then you will have less issues with email delivery.
If you use a Digital Ocean server, you can set up reverse DNS for your domain name by naming your droplet the same as your domain name, and then wait a few hours and try again. If you use other cloud providers then it may be a similar process. You will need to try or check with there support.
If you don't have the host command on your server, you can install it with,
apt-get install dnsutils
yum install bind-utils
You can also try setting your servers host name.
hostnamectl set-hostname your-domain.tld
Check your mail spool for any SMTP rejection messages. eg,
Try using email@example.com as the sender
If you want to send as a different user, eg firstname.lastname@example.org, you can set up an alias in the file /etc/aliases. eg,
You may need to create a MX record for your domain at your DNS provider. Use https://dnschecker.org/#MX or https://mxtoolbox.com to check for propagation for your-domain.tld
your-domain.tld. 7200 IN MX 10 zabbix.your-domain.tld.
Also try checking your log files for any clues
cat /var/log/mail.log (Ubuntu) cat /var/log/maillog (Centos)
Check the postfix service status that it is running
sudo service postfix status
Try Postfix check
Check your domain name resolves to the ip of your zabbix server. eg,
Do a reverse lookup (replace the #'s with your ip address).
If you created your server using Digital Ocean, name your droplet, the same as your domain name.
Try pinging your destination email address domain from your server. eg,
If you ever need to rerun the postfix configuration wizard (Ubuntu), then run
sudo dpkg-reconfigure postfix
Note that this is only a minimal SMTP setup designed to demonstrate sending emails from Zabbix. Avoiding the SPAM folder for all possible email providers is a major task and outside the scope of this course. Usually as the Administrator, you are the recipient of the emails so you have the options in your email clients to set up rules to sort incoming messages and add senders to safe lists. The next thing you could also try is to add an SPF record for your domain.
Also, you can continue on with the course and try other forms of message delivery such as SMS, Slack and Telegram which are discussed in the next few lessons.