Use The Email Media Type And Create A Send Only SMTP Server

Video Lecture

Use The Email Media Type And Create A Send Only SMTP Server Use The Email Media Type And Create A Send Only SMTP Server Use The Email Media Type And Create A Send Only SMTP Server

Description

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

On Ubuntu,

1
sudo apt install mailutils

On Centos,

1
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.

1
ping zabbix.your-domain.tld

Note

Of course, replace your-domain.tld with your actual domain. eg, zabbix.seanwasere.com

Then configure postfix by calling

1
sudo nano /etc/postfix/main.cf

scroll to the bottom, and set

1
2
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.

1
2
3
myhostname = zabbix.your-domain.tld
mydomain = your-domain.tld          #<---note that the subdomain part is removed here
mydestination = $myhostname, localhost.localdomain, localhost

restart postfix

1
sudo systemctl restart postfix

Try sending an email from the command line,

Ubuntu 18

1
echo "This is the body" | mail -s "This is the subject" -a "FROM:root@your-domain.tld" your@email-address

Centos 7

1
echo -e "Subject: This is the subject\n\nThis is the body\n" | sendmail -f root@your-domain.tld -v your@email-address

Minimal Email Media Type Settings in Zabbix UI

Minimal Email Media Type Settings in Zabbix UI

Troubleshooting

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.

eg

1
host zabbix.your-domain.tld

> zabbix.your-domain.tld has address 111.222.333.444

Then do the reverse look up

1
host 111.222.333.444

> 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,

Ubuntu 18

1
apt-get install dnsutils

Centos 7

1
yum install bind-utils

You can also try setting your servers host name.

1
hostnamectl set-hostname your-domain.tld

Check your mail spool for any SMTP rejection messages. eg,

1
cat /var/spool/mail/root

Try using root@your-domain.tld as the sender

If you want to send as a different user, eg zabbix@your-domain.tld, you can set up an alias in the file /etc/aliases. eg,

1
zabbix:         root

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

1
your-domain.tld.         7200    IN      MX      10 zabbix.your-domain.tld.

Also try checking your log files for any clues

1
2
cat /var/log/mail.log   (Ubuntu)
cat /var/log/maillog    (Centos)

Check the postfix service status that it is running

1
sudo service postfix status

Try Postfix check

1
postfix check

Check your domain name resolves to the ip of your zabbix server. eg,

1
ping zabbix.your-domain.tld

Do a reverse lookup (replace the #'s with your ip address).

1
host ###.###.###.###

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,

1
ping my-email-address-domain.com

If you ever need to rerun the postfix configuration wizard (Ubuntu), then run

1
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.

Useful Sites

Postfix Basic Configuration

Macros