Last modified: Apr. 1, 2009
Contents
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
/usr/sbin/mailstats
/usr/sbin/makemap
/usr/sbin/praliases
/usr/sbin/sendmail.sendmail
/usr/sbin/smrsh
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 sendmail.cf /etc/rc.d/init.d/sendmail
# config: /etc/mail/sendmail.cf
# strings /usr/sbin/sendmail.sendmail | grep sendmail.cf
/etc/mail/sendmail.cf
# rpm -ql sendmail-* | grep sendmail.cf
/etc/mail/sendmail.cf
# rpm -ql sendmail-* | grep sendmail.mc
/etc/mail/sendmail.mc
Get the hostname of the computer.
# hostname
server.test.com
Backup the default configuration file and make the following changes.
define(`SMART_HOST',`mail.test.com')
define(`confCW_FILE', `-o /etc/mail/local-host-names')
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
dnl DAEMON_OPTIONS(`port=smtp,Addr=::1, Name=MTA-v6, Family=inet6')dnl
FEATURE(`masquerade_envelope')dnl
FEATURE(`genericstable',`hash -o /etc/mail/genericstable.db')
GENERICS_DOMAIN_FILE(`/etc/mail/generics-domains')
# sudo mkdir -p /root/backups/originals
# sudo cp -Rp /etc/mail/ /root/backups/originals/mail/
# cd /etc/mail
# sudo vi sendmail.mc
Create the generics-domains file with the following so that you can rewrite
your (envelope) From: address for your host.
server.test.com
# 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.
root noreply@test.com
# 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.
server.test.com
server
# 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/sendmail.pid
6395
/usr/sbin/sendmail -bd -q1h
4 - Example shell script
Here is an example shell script that sends an email.
#!/bin/sh
clear=/usr/bin/clear
echo=/bin/echo
mail=/bin/mail
hostname=/bin/hostname
host=`$hostname`
date=/bin/date
current_time=`$date +%H:%M`
current_day=`$date +%m/%d/%Y`
recipient="testuser@test.com"
subject="Test sent from $host"
body="This is a test. It was sent at $current_time on $current_day."
$clear
$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...
|