Configuring
Sendmail
By
Anurag Phadke
Here
are some hands-on steps for configuring sendmail,
the most popular Unix-based implementation of the
Simple Mail Transfer Protocol for transmitting e-mail
E-mail
has revolutionized mass communication by making it
fast, reliable and affordable. Born in the days of
ARPANET, even before the Internet was standardized,
e-mail happened to be the only cause for people opting
for an Internet connection. Starting from a few hundred
mails per day in its youth at Berkeley University,
more than 1 million e-mails make their trips round
the globe every day. So just how simple or tough it
is for servers to handle such a huge amount of load?
Here are some hands-on steps for configuring sendmail,
the most popular Unix-based implementation of the
Simple Mail Transfer Protocol for transmitting e-mail.
Down to basics
Sendmail developers have done just the right thing
by doing away with things that caused trouble in the
past such as "Relaying e-mails to each and every
domain." Though the option still prevails, one
needs to enable it in the conf files. That's one up
against SPAM! Version 8.9 and above support MSA (Mail
Submission Agent) which listens on connections made
at port 587. This is a relatively new concept used
by POP/IMAP clients like Eudora in place of SMTP.
Specific host can be enabled by /etc/mail/relay-domains
file. Normally, entries in this file represent entire
domains that are allowed to relay. However, if you
want to list specific hosts in this file and not subdomains,
you can use FEATURE (relay_hosts_only).
Installing and Configuring Sendmail
You can download the latest version of sendmail from
ftp://ftp.sendmail.org/pub/sendmail
Here's the procedure for installing sendmail:
#cp sendmail.8.11.4.tar.gz / 'copies sendmail to /
directory
#tar zxvf sendmail.8.11.4.tar.gz 'untars sendmail.
By default, it gets untarred in the /sendmail-8.11.4
directory
#rm /sendmail.8.11.4.tar.gz 'removes sendmail from
/ directory
#cd /sendmail-8.11.4/ 'changes to /sendmail/ sendmail.x.x.x
directory
#sh Build 'Compiles and Builds sendmail
Above commands will install sendmail along with its
configuration files
in the default directories. Configuration and .mc
files are installed in
/etc/mail/ directory.
Difference between .cf and .mc files is similar to
the difference between English and Greek language.
.cf is more of a cryptic language, can be easily parsed
and cannot be understood by a normal person. On the
other hand, .mc files are written in "English"
though they are a bit slow at getting parsed out.
A first hand look at /etc/mail/sendmail.mc can be
head spinning. So, we have tried to explain out some
of the basic yet important features that must be included/edited
in the sendmail.mc file.
dnl (delete through newline) omits the new line character,
reducing the time require to parse through the file.
OSTYPE(`linux'): Defines the OS on which sendmail
is running. Can be changed to other OS such as HPUX
or Solaris.
MAILER(`SMTP'): Use SMTP (Send Mail Transfer Protocol)
for sending emails over the Internet.
MAILER(`local') : Mails on the same server should
be delivered locally.
define(`confTO_CONNECT', `1m'): Connect to the server
at a 1 minute interval.
define(`ALIAS_FILE', `/etc/aliases'): Path where alias
file resides.
define(`confMax_Message_size', '2000000'): Maximum
size of the email that can be delivered.
define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun'):
These are the privacy flags which issue authorization
warnings, allow only root to run sendmail.
define(`confAUTH_OPTIONS', `A'): The ".mc"
file allows
values to be assigned from one variable to another.
In the above case, value of "A" is assigned
to "confAUTH_OPTIONS". (confAUTH_OPTIONS=A)
FEATURE(use_CW_FILE): The list of domains for which
mail should be delivered locally. This line is important
if you are doing virtual hosting on your server.
FEATURE(`access_db'): Uses a macro file with the name
"access_db". Explained below in detail.
Insert/Edit the lines in accordance with your requirement.
The sendmail.mc file now needs to be converted to
sendmail.cf in order to be understood by the machine.
This can be achieved by the following command:
#m4 /etc/mail/sendmail.mc > /etc/sendmail.cf
Presence of sendmail-cf rpm is a prerequisite for
using the m4 option.
We now need to focus our attention on some of the
other files that exist in the /mail/etc directory.
access: It contains vital information about handling
the received emails. A basic access file along with
the response that it should return is mentioned below.
spammer@bahbah.com ERROR:"550 We hate spammers"
'shall return an email back to we the above mentioned
error.
spam@bah.com Reject 'Rejects email from spam@bah.com
blah.com OK 'Accepts email from blah.com
[127.0.0.1] RELAY 'Relays messages originating from
127.0.0.1 (local machine)
Save the file. You shall now need to update sendmail
with the newly created access file using the following
command:
#makemap hash /etc/mail/access < /etc/mail/access
virtusertable: While doing virtual hosting, many hosts
offer the option of forwarding e-mails to a different
address or provide unlimited e-mail id's such as any@bah.com,
info@bah.com and forward them to a single
e-mail address. The file virtusertable is used for
this
purpose. After editing this file, you once again need
to
run the "makemap" command as shown for the
"access"
file.
info@bah.com foo-info 'Forwards emails to the username
foo-info on the server.
notexist@bahbah.com error:nouser No such user here
'Sends an email to the sender with the subject No
such user here
@blahblah.org me@bah.org 'Forwards emails from the
domain blahblah.org to me@bah.org
Make sure that you have configured your machine using
proper IP address and DNS entries. If not, run "linuxconf"
from the shell and make appropriate changes in the
Basic Host Configuration menu. You also need to edit
the /etc/hosts file in accordance to the entry made
in the Basic Host Configuration.
Sample: /etc/hosts file
#IP address localhost localhost.localdomain
127.0.0.1 bahbah bahbah.com
Now that you are through with the setup of "sendmail",
you need to know how to start, restart, stop and know
the status of sendmail on your server. For this copy
the code given inside the box, to /etc/init.d/sendmail.
The command and response following it is mentioned
below:
#./etc/init.d/sendmail start
Starting sendmail: [ OK ]
To test if the server started up alright, telnet to
yourself on port 25 by
typing
#telnet 127.0.0.1 25
If it is functioning properly you will see something
like this:
Trying 127.0.0.1...
Connected to 127.0.0.1
Escape character is '^]'.
220 127.0.0.1 ESMTP Sendmail 8.11.2/8.11.2; Sat, 21
Jul 2001 03:50:33 +0530
If you are able to see this, then Sendmail has been
successfully
setup on your server.
Anurag Phadke Can be reached at cbca@mantraonline.com
Check
Spamming
A good Web host, ensures that his customers are always
protected from services that they didn't opt for.
When a single person receives "SPAM" he/she
can simply delete it, but when all the users on a
particular machine are greeted with "SPAM"
it not only places load on the server but also consumes
disk space and queues up e-mail. One can prevent spamming
by updating the "access_db" file regularly.
http://mail-abuse.org/rbl/ keeps a regular track of
spammers and is a good reference point.
Using Sendmail for Web Hosting
Comments/Feedback forms are essential for maintaining
good customer relationship over the Web. Your customers
can use "sendmail" installed on the server
via the "cgi-bin" directory. The line(MAIL,
"|/usr/sbin/sendmail -t") || return 0; tells
your cgi script that sendmail is installed in "/usr/sbin/sendmail"
directory and can be used for sending mails from the
website.
#!/bin/bash
#
# sendmail This shell script takes care of starting
and
stopping sendmail.
#
# chkconfig: 2345 80 30
# description: Sendmail is a Mail Transport Agent,
which is
the program \ that moves mail from one
machine to another.
# processname: sendmail
# config: /etc/sendmail.cf
# pidfile: /var/run/sendmail.pid
# Source function library.
. /etc/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Source sendmail configureation.
if [ -f /etc/sysconfig/sendmail ] ; then
. /etc/sysconfig/sendmail
else
DAEMON=no
QUEUE=1h
fi
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit
0
[ -f /usr/sbin/sendmail ] || exit 0
RETVAL=0
prog="sendmail"
start() {
# Start daemons.
echo -n $"Starting $prog: "
/usr/bin/newaliases > /dev/null 2>&1
for i in virtusertable access domaintable
mailertable ; do
if [ -f /etc/mail/$i ] ; then
makemap hash /etc/mail/$i
<
/etc/mail/$i
fi
done
daemon /usr/sbin/sendmail $([ "$DAEMON"
= yes
] && echo -bd) \
$([ -n "$QUEUE" ] && echo -q$QUEUE)
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/
sendmail
return $RETVAL
}
stop() {
# Stop daemons.
echo -n $"Shutting down $prog: "
killproc sendmail
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/
sendmail
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
RETVAL=$?
;;
condrestart)
if [ -f /var/lock/subsys/sendmail ]; then
stop
start
RETVAL=$?
fi
;;
status)
status sendmail
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|
status}"
exit 1
esac
exit $RETVAL