Configuring email for system event notification in Red Hat Enterprise Linux

Last modified: Apr. 1, 2009

1 - Summary
2 - Sendmail installation
2 - Service configuration
3 - Example shell script
4 - Service check

1 - Summary

This guide will show you how to configure email using the mail utility for
system event notication in Red Hat Enterprise Linux. Mail is a command line
utility that sends email using SMTP. This has been tested in Red Hat
Enterprise Linux 5.

2 - Sendmail installation

Install the following Red Hat packages in order.
# sudo rpm -ivh cyrus-sasl-*.rpm
# sudo rpm -ivh sendmail-*.rpm
# sudo rpm -ivh sendmail-cf-*.rpm

3 - Service configuration

Find where the sendmail daemon was installed to.
# rpm -ql sendmail-* | grep sbin

Enable the sendmail service so that it will start when the system starts up.
# sudo /sbin/chkconfig sendmail on
# sudo /sbin/chkconfig --list sendmail
sendmail        0:off   1:off   2:on    3:on    4:on    5:on    6:off

Find where the configuration file should be put.
# grep /etc/rc.d/init.d/sendmail 
# config: /etc/mail/
# strings /usr/sbin/sendmail.sendmail | grep
# rpm -ql sendmail-* | grep
# rpm -ql sendmail-* | grep

Get the hostname of the computer.
# hostname

Backup the default configuration file and make the following changes.
  define(`confCW_FILE', `-o /etc/mail/local-host-names')
  dnl DAEMON_OPTIONS(`Port=smtp,Addr=, Name=MTA')dnl
  dnl DAEMON_OPTIONS(`port=smtp,Addr=::1, Name=MTA-v6, Family=inet6')dnl
  FEATURE(`genericstable',`hash -o /etc/mail/genericstable.db')
# sudo mkdir -p /root/backups/originals
# sudo cp -Rp /etc/mail/ /root/backups/originals/mail/
# cd /etc/mail
# sudo vi

Create the generics-domains file with the following so that you can rewrite
your (envelope) From: address for your host.
# sudo vi generics-domains

Create the following file which contains the mapping between your local email
address and your external one. We will use the root user so you might want to
change the comment field in /etc/passwd appropriately.
# sudo /usr/sbin/vipw
# sudo vi genericstable

Add the following to the local-host-names file so that the computer can
deliver email to local users.
# sudo vi local-host-names

Rebuild the configuration files.
# sudo make

You will need to configure SELinux appropriately. SELinux status can be
found by running sestatus.
# sudo /usr/sbin/sestatus | grep status:
SELinux status:                 enabled

Start the sendmail service.
# sudo /sbin/service sendmail start
Starting sendmail: [  OK  ]
Starting sm-client: [  OK  ]
# sudo cat /var/run/
/usr/sbin/sendmail -bd -q1h

4 - Example shell script

Here is an example shell script that sends an email.


current_time=`$date +%H:%M`
current_day=`$date +%m/%d/%Y`
subject="Test sent from $host"
body="This is a test. It was sent at $current_time on $current_day."

$echo $body | $mail -s "$subject" $recipient
exit 0

5 - Service check

Reboot your computer. Log in like normal and check to see that the sendmail
service is running. That's it, now you have configured email for system event
notification in Red Hat Enterprise Linux.
# sudo /sbin/shutdown -r now
# sudo /sbin/service sendmail status
sendmail (pid 4572 4559) is running...

Last modified: Thu Jan 1 00:00:00 1970 UTC
Packetwatch Research 2002-2018.