Change email address from which Nagios sends messages

In some cases you want to change default email address of anonymous@hostname from which Nagios sends notifications. This can easily be done by changing following directives in Nagios configuration files.
1. Open the main Nagios configuration file nagios.cfg and edit the line containing admin_email

vim nagios.cfg
admin_email=nagios@localhost  # change to your desired smtp address

2. Edit commands.cfg file and edit “notify-host-by-email” directive by adding -f$ADMINEMAIL$ at the end

vim commands.cfg
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/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$ -f$ADMINEMAIL$

2. Edit same file – commands.cfg and this time edit notify-service-by-email by adding -f$ADMINEMAIL$ at the end

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$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ -f$ADMINEMAIL$

3. Restart Nagios services

service nagios restart

You are done !