Thursday, July 15, 2010

Nagios - Use an external smtp server to send notifications

One of the most important feature of Nagios is the notification system; by default Nagios will use the local mail daemon (mail) to send all the notifications.
Maybe this kind of system was working fine in past, but today, with this huge amount of spam circulating all over the world, this kind of emails from a not verified source can be filtered by the same company antispam system.
In order to avoid this issue I will explain how to configure Nagios using an external smtp server also with smtp authentication.

Since the Nagios notification event is still a triggered command, we have to download an alternative command line email client.

I suggest the powerful "sendemail" command, available at the following link:

Once the download is finished unpack sendemail:

[root@localhost] tar -xvf sendEmail-v1.56.tar.gz

Then copy the binary in the bin folder

[root@localhost] cp /root/sendEmail-v1.56/sendEmail /usr/local/bin/

In order to troubleshoot any eventual problem, please use the following workaround to create and give the necessary authorization to write in the sendemail log file:

[root@localhost] touch /var/log/sendEmail
[root@localhost] chmod 666 /var/log/sendEmail

(remember, by default, Nagios does not start with full administrative rights, so command sent by Nagios too)
Now we need to set some variables that we need to recall later depending on your particular environment and smtp configuration:

So edit the resource.cfg file located in:
Add the following lines with your particular smtp configuration:



#If you don't use smtp authentication skip this variables and use the version B) of commands.cfg


Save and exit (<- This commands change depending from your editor, sadly I've been in too many disputes aboute which linux editor is better, so don't expect any advice from me) After this, we are gonna change the commands.cfg file located in:

First perform a backup of the config file:
cd /usr/local/nagios/etc/objects/
cp commands.cfg commands.cfg.old

Edito the commands.cfg file and you will find two commands:
'notify-host-by-email' and 'notify-service-by-email'

Now, if you use SMTP authentication replace the two commands with the following:

# 'notify-host-by-email' command definition define command{ command_name notify-host-by-email command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/local/bin/sendEmail -s $USER7$ -xu $USER9$ -xp $USER10$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" }

# 'notify-service-by-email' command definition define command{ command_name notify-service-by-email command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/local/bin/sendEmail -s $USER7$ -xu $USER9$ -xp $USER10$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" }

This is pretty much the same but without passing the authentication triggers to sendemail:

# 'notify-host-by-email' command definition define command{ command_name notify-host-by-email command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/local/bin/sendEmail -s $USER7$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" }

# 'notify-service-by-email' command definition define command{ command_name notify-service-by-email command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/local/bin/sendEmail -s $USER7$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" }

Now the configuration is finished. Anyway, before applying the new configuration, run the following command to check for any error or mistake:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If there are no errors, restart the nagios service:

service nagios restart

To troubleshoot the sendemail command run the following to check in the log file:

tail -f /var/log/sendEmail

Hope this post will be useful to you. If you have any troube or you want to suggest me a better system do not hesitate to write a line.



  1. Great post - I wanted nagios posting to a google apps address, so I needed to add -o tls=yes and it worked a treat!

  2. Hi Daniele,

    I have configured everything as mentioned, now i'm getting the following error, could please help me out.

    ERROR => Received: 530 5.7.0 Must issue a STARTTLS command first.

  3. To issue STARTTLS add the following option to sendEmail command:

    -o tls=yes

  4. Thank you so much! I just couldn't get smtp email working in Nagios, and this worked perfectly! :-)

  5. Thank you and I would recommend your post to my friends ..

  6. Hi all

    > tail -f /var/log/sendEmail

    Oct 21 12:33:57 localhost sendEmail[17463]: NOTICE => Authentication not supported by the remote SMTP server!
    Oct 21 12:33:57 localhost sendEmail[17463]: ERROR => Received: 530 5.7.0 Must issue a STARTTLS command first. a10sm3904486paw.17

    i getting error;
    if this parameter is requiter then where put this(File name,command) -o tls=yes

  7. Its not working for me.

    Error: Unexpected start of object definition in file '/usr/local/nagios/etc/objects/commands.cfg' on line 33. Make sure you close preceding objects before starting a new one.
    Error processing object config files!

    Can u PLEASE help me?

  8. Hi, I am trying to configure it with gmail. But I am not getting anything in logfile. When I run this from command line

    #ll |sendEmail -f -u TEST -m Test -s -xu -xp Testing$#@! -t -o tls=yes

    I am getting this error.
    Apr 06 02:43:00 localhost sendEmail[29533]: ERROR => Timeout while reading from There was no response after 60 seconds.

    When I use #telnet 465, it works. Please guide me what to do

  9. hi, i'm trying to configure it with my work mail. the command work when i issue it from the command line, it doesn't when i set it up in Centreon/nagios. i've done all the above config, but still doesen't work.


    1. This comment has been removed by the author.

    2. Hi Erjol,

      I had some problems with the Centreon/Nagios too. But I sorted it out.

      Im not sure if its too late. But if u still have the issue, could you post ur error message ?

  10. Hi Daniele Cuocci

    Thanks for a great blog :)

    sendEmail stopped working after a reboot, how do I get it up and running again? I can't see sendEmail service in server --status-all :( Hope you can help

  11. Nice post with great details. I really appreciate your work Thanks for sharing.

    desktop notification software

  12. Hi, Please help... I've setup an instance of Fully Automated Nagios (FAN) and followed your guide. I can send an email from the CLI using sendEmail but Nagios isn't able to send any notifications. I have setup the configurations using the Centrion web interface. It's as if Nagios is not executing what it needs to when an alarm is triggered because I'm getting no sendEmail log activity. I need to troubleshoot further but don't know where to start. I'm hoping someone else encountered the issue with FAN... Can anyone point me in the right direction?

  13. thank you. still working....;-)

  14. Benefits of an SMTP server

  15. Benefits of an SMTP server

  16. try fullyautomatednagios , its ready to install ISO. You can download fan nagios from and installation guide is also there.

  17. You have nice blog on webhooks. Thanks for sharing very informative details on webhooks.
    transactional email
    email sending service
    what are webhooks


  18. Very interesting blog post.Quite informative and very helpful.This indeed is one of the recommended blog for learners.Thank you for providing such nice piece of article. I'm glad to leave a comment. Expect more articles in future. You too can check this DevOps tutorial for updated knowledge on DevOps.

  19. Hi Daniele,
    I am facing problem to copy paste command in command.cfg, Should i replace \n by new Line?

  20. hi, i got error
    ERROR => Can't use improperly formatted email address:

  21. For the resolution of Gmail attachment failure error, the user should run the updated version of adobe flash the browser should be updated to the latest version also the user should try accessing on another system. If nothing helps then the user should get the issue resolved with the help of a team of trained and certified Gmail experts.
    Gmail Customer Care UK

  22. As used by countless online gamers worldwide, a lot of people have no concept what an activity server is best ark survival server hosting

  23. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site. SMTP Server for Bulk Mailing

  24. Hello Daniel, it's an amazing post about SMTP. It provide information about SMTP server .your blog provide knowledgeable post. SMTP plans must visit from buckethost .