Changing sender’s email address in Nagios

By default settings, Nagios will send email notifications as nagios@localhost, identified by $ADMINEMAIL$ macro.

If you want to change this behavior, you need to set the email address you want to use in the nagios.cfg file:

# The email and pager address of a global administrator (likely you).
# Nagios never uses these values itself, but you can access them by
# using the $ADMINEMAIL$ and $ADMINPAGER$ macros in your notification
# commands.

You also need to edit the commands.cfg file and add -r $ADMINEMAIL$ to notify-host-by-email and notify-service-by-email commands right after /usr/bin/mail:

# '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/bin/mail -r $ADMINEMAIL$ -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
# '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/bin/mail -r $ADMINEMAIL$ -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$

If you don’t want to change your nagios.cfg, you can directly specify the email address in commands.cfg:

[...] /usr/bin/mail -r -s [...]