msmtp + Zabbix + Gmail!

My company uses Gmail for all our email accounts. We’ve found that with the limited IT budget and staffing it’s easiest for us to use google to manage all our corporate email.

I’ve been trying to get Zabbix to send emails using Gmail, of course since gmail only uses TLS it’s been a bit of a problem since Zabbix does not support this out of the box. I decided to use msmtp and a Zabbix script to handle it all.

Note: We’re using VZ servers so some commands may be different.

First thing to do was to install all the correct packages:
vzyum 103 install gnutls gnutls-devel cyrus-sasl Libidn fetchmail

After those were installed I had to download MSMTP from the sourceforge page here.

Configure, make, make install with your options. I used:
./configure --with-ssl=gnutls

Next I created an msmtp_wrapper.conf file in the Zabbix bin directory like the following:
defaults
syslog LOG_MAIL
account default
host smtp.gmail.com
port 587
tls on
auth on
user helpdesk@mydomain.net
password MYPASSWORD
auto_from on

Next I created the msmtp_wrapper file in the Zabbix bin directory :
#!/bin/bash
echo "Subject:$2+$3" | tr "+" "\n"> /tmp/message.zabbix
/usr/local/bin/msmtp -t -C /home/zabbix/bin/msmtp_wrapper.conf --tls-certcheck=off -- $1 < /tmp/message.zabbix rm /tmp/message.zabbix

Change the owner and permissions on these files as such:
chown zabbix:zabbix msmtp_wrapper*
chmod a+x 700 msmtp_wrapper*

Next create a media type in Zabbix with the script name you used.

Lastly, setup some triggers to use it!

That should be all that you need to get started.