View Full Version : Authenticated SMTP How-To
Here is a quick guide to setting up authenticated SMTP with Zabbix:
As Zabbix doesn't natively support authenticated SMTP, you'll need to call an external SMTP client to do this for you. I use NBSMTP as a light-weight SMTP client...
1) Download the latest version of nbsmtp
http://nbsmtp.ferdyx.org/
2) Compile nbsmtp with the following options (using /usr/local/nbsmtp as an example installation directory)
./configure --prefix=/usr/local/nbsmtp --enable-ssl
make
make install
3) Create an script that can be called from Zabbix (by default, scripts are located in the zabbix/bin directory). Let's call this script smtp-auth
smtp-auth should contain something like the following (change the variables to suit you. $1,$2,$3 are variables you set in the Zabbix PHP front end)
#!/bin/sh
export smtpemailfrom=myemail@mydomain.com
export zabbixemailto=$1
export zabbixsubject=$2
export zabbixbody=$3
export smtpdomain=mydomain.com
export smtpserver=mail.mydomain.com
export smtplogin=mylogin
export smtppass=mypass
echo "From: \"Zabbix Monitor\" <$smtpemailfrom>" > /tmp/mymailinput
echo "To: $zabbixemailto" >> /tmp/mymailinput
echo "Subject: $zabbixsubject" >> /tmp/mymailinput
echo "" >> /tmp/mymailinput
echo "This is an automated alert from Zabbix Network Monitoring. The mess
age is $zabbixbody" >> /tmp/mymailinput
/usr/local/bin/nbsmtp -d $smtpdomain -f $smtpemailfrom -h
$smtpserver -U $smtplogin -P $smtppass-S < /tmp/mymailinput
Save the smtp-auth script and make sure that it is executable. You can create a dummy /tmp/mymailinput script to test that you can successfully send email through your authenticated smtp server.
So, the way this now works is that when an alert/action occurs in Zabbix, it should now call the smtp-auth script. Zabbix should pass in values for $1, $2, $3, the script calls nbstmp, and nbsmtp accepts the message in standard smtp format from /tmp/mymailinput.
Mark
nick5000
06-07-2006, 16:51
Well done. Thank you!
Alternatively you can use sendEmail.
1) apt-get install sendEmail
2) Create a script "zabbix_sendemail" (chmod 755) in the AlertScriptsPath folder specified by /etc/zabbix/zabbix_server.conf
--------------------------------------
#!/bin/sh
export smtpemailfrom=zabbix@yourdomain.com
export zabbixemailto=$1
export zabbixsubject=$2
export zabbixbody=$3
export smtpserver=yoursmtpserver.com
export smtplogin=smtpuser
export smtppass=smtppassword
/usr/bin/sendEmail -f $smtpemailfrom -t $zabbixemailto -u $zabbixsubject -m $zabbixbody -s $smtpserver:25 -xu $smtplogin -xp $smtppass
--------------------------------------
3) Set the Action (Configurations / Actions in the php frontend)
4) Set the Media Type (Administration / Media types in the php frontend) script to zabbix_sendemail
5) Add the Media to the user (Administration / Users / user in php frontend)
raghaven.kumar
02-07-2009, 17:39
Thanks to you both guys.
:cool:
I got a solution.
Will this method be implemented into Zabbix in future?
Thanx! It works well (I use second solution with sendEmail, which I consider as simpler one).
Best regards,
Skygge.
Hey guys,
HEre is my contribution for my first post.
I solved the same issue with "delegate" wich emulate all kinds of proxy :
1) Download delegate on the website or from your repositories ;
2) Compile it if you have to, it's so simple : "make" on the folder ;
3) "mv" it from ./src/ to /usr/bin/ directory
4) run => delegated -v SERVER="smtp://yoursmtp.com" -P25 MYAUTH=$USER:$PW
5) Its ok, you just have to set up localhost has your smtp server in zabbix
I can put the init.d script if someone is interested
tekknokrat
10-07-2009, 14:55
the easiest and flexible solution to workaround smtp authentication ist to install a local mailer acting as smarthost. Suggestions for mailer daemon exim4 or postfix.
I'm agree for the flexible but not for the easiest !
Everyone has'nt the knowledge to install an MTA.
I've spent some night trying to install postfix and I prefere munch more to have a proxy.
tekknokrat
10-07-2009, 15:29
your right with postfix. If you use debian/ubuntu its easiest to go with exim4.
You only need to configure for satellite and add credentials to the passwd.client.
your right with postfix. If you use debian/ubuntu its easiest to go with exim4.
You only need to configure for satellite and add credentials to the passwd.client.
Honesly, if you can do a 6 step tutorial, for a secured and closed smtp server with the nice redirection to an authenticated server, I'll switch to exim4 and you'll help a lots of people :)
thanks brow, this really helps.
:):):):)
Hi, I am not sure if this is helpful, but I have found this page that talks about various kinds of email authentication and SMTP http://www.smtp.com/corporate.html -- you have to scroll down to the section called "Reputation Guard". Sorry if this is not helpful, it might be coals to Newcastle. :)
Can you put the script of delegated?
Thanks
kerridge0
14-08-2010, 22:51
Thank you for this,
in case it's useful to anyone, I followed the sendEmail recipe but it failed silently.
I had to enclose the arguments inside quotes as per http://www.zabbix.com/forum/showpost.php?p=49130&postcount=6
also I had to refer to the script by name, not full path.
Thyagaraj
13-09-2010, 17:05
I used dreas simple script and my zabbix audit>action logs showing that the mail is sent but I'm not receiving the mail
Here is my modified script:
#!/bin/sh
export smtpemailfrom=zabbix@localhost
export zabbixemailto=$1
export zabbixsubject=$2
export zabbixbody=$3
export smtpserver=localhost
export smtplogin=thyagaraj03@gmail.com
export smtppass=my-gmail-password
/usr/bin/sendEmail -f $smtpemailfrom -t $zabbixemailto -u $zabbixsubject -m $zabbixbody -s $smtpserver:25 -xu $smtplogin -xp $smtppass
When I manually execute the script replacing "export zabbixemailto=$1" with export zabbixemailto="thyagaraj@gmail.com", I'm getting the following:
Sep 13 19:31:55 karmic9 sendEmail[14887]: Message input complete.
Sep 13 19:31:55 karmic9 sendEmail[14887]: NOTICE => Authentication not supported by the remote SMTP server!
Sep 13 19:31:56 karmic9 sendEmail[14887]: Email was sent successfully!
I can see mail in my inbox.
FYI,
I have postfix installed with gmail relay.
Plz need help
kerridge0
13-09-2010, 18:39
did you put all three arguments in quotes?
as per http://www.zabbix.com/forum/showpost.php?p=49130&postcount=6
e.g.
..
export zabbixemailto="$1"
export zabbixsubject="$2"
export zabbixbody="$3"
..
I can't comment on the postfix part of it because it's all greek to me...
Thyagaraj
14-09-2010, 16:04
Is there any way so that I force zabbix to send email
Thyagaraj
15-09-2010, 12:44
Yes, after putting in quotes it's working on one machine and on another machine it's not working, facing same problem even after putting quotes. In Audit>actions it is showing that the message is sent but it is not in the inbox
Yes, after putting in quotes it's working on one machine and on another machine it's not working, facing same problem even after putting quotes. In Audit>actions it is showing that the message is sent but it is not in the inbox
i have the same problem too..
but i think it depends on the error message, its a single-line it works for example:
{TRIGGER.NAME}: {STATUS}
but it dont works in mulitple lines, for example:
{DATE} - {TIME}
Host: {HOSTNAME}
Auslöser: {TRIGGER.NAME}: {STATUS}
last Value: {ITEM.LASTVALUE}
have somebody an idea how can i fix it?! i use sendEmail..
export zabbixemailto="$1"
export zabbixsubject="$2"
export zabbixbody="$3"
tekknokrat
03-05-2011, 18:43
Honesly, if you can do a 6 step tutorial, for a secured and closed smtp server with the nice redirection to an authenticated server, I'll switch to exim4 and you'll help a lots of people :)
After 2 years ;) a simple setup using exim4 (debian/ubuntu packages) in 6 steps:
1. apt-get install exim4-daemon-light
2. In postconfig dialog select the "smarthost; no local mail" setup
Configure the smtp server of your email provider as smarthost.
Alternatively you can hold your config like this:
/etc/exim4/update-exim4.conf
dc_eximconfig_configtype='satellite'
dc_other_hostnames='yourhost'
dc_local_interfaces='127.0.0.1 ; ::1'
dc_readhost='yourhost'
dc_relay_domains=''
dc_minimaldns='false'
dc_relay_nets=''
dc_smarthost='your.providers.smtp.server.here'
CFILEMODE='644'
dc_use_split_config='true'
dc_hide_mailname='true'
dc_mailname_in_oh='true'
dc_localdelivery='mail_spool'
3. modify /etc/email-addresses:
# Add this entry
zabbix: your@sender.email.address.here
4. modify /etc/exim4/password-file:
# Add this entry
your.providers.smtp.server.here:yoursmptusername:y oursmptpassword
5. /etc/init.d/exim4 reload
6. Zabbix email setup will finally only consists of a single localhost (or more explicitly for ipv4 127.0.0.1) entry without credentials given. Every mail the user "zabbix" sends is now relayed to external via your providers smtp server.
Bill Wang
16-06-2011, 18:11
Mark this thread, I'll try the second solution later