sendmail hint update
jjones at darkside.dynup.net
Mon Jul 9 17:13:25 PDT 2001
* Fixed libdb install (it's done properly now).
* Added an MUA issue to the common problems.
-------------- next part --------------
LFS VERSION: Any
AUTHOR: J. Jones jjones(at)darkside(dot)dynup(dot)net
This hint covers the building, configuring, and use of Sendmail.
Software you need
Sendmail (duh): ftp://ftp.sendmail.org/pub/sendmail/
I recommend the latest 8.11 (8.11.4 at this time).
This will be used as our local delivery agent.
Berkeley DB: http://www.sleepycat.com/
Sendmail uses this (libdb) to store much of it's configuration.
Use the latest 3.* version (3.2.9 currently).
Building the required packages
Unpack the source tarball, cd into the build_unix/ subdirectory of the directory
created. From here, run the following:
../dist/configure --prefix=/usr --enable-compat185
../dist/configure --prefix=/usr --enable-compat185 --enable-shared
make docdir=/usr/doc/Berkeley-DB install
cp libdb.a /usr/lib/
We do this twice because the source tree won't build both a shared and a
static library at the same time. You could optionally build either one, but
having both is probably best.
If you wish to add optimization flags to this package, you will have to edit
either 1) the configure script, if you have the $CFLAGS variable set, or 2)
the Makefile after ./configure has generated it. For the previous, (with
version 3.2.9), change line 994 to CFLAGS="$CFLAGS -DGNU_SOURCE".
Unpack the source tarball, cd into the directory it created. From here, run
Procmail will look for a sendmail file anywhere in the $PATH. If it doesn't
exist, it will prompt you for it. Touching the file will allow it to find
sendmail in the location where we will later install it.
NOTE: m4 is very picky.. pay close attention, and realize that these are
not standard single quotes.
Unpack the source tarball, cd into the directory it created.
Edit the file devtools/OS/Linux. At the end of this file, add the following
You can also define/change the optimization flags here. By default, we will
be building the 'OPTIMIZED' variant, so this is the only one you need to edit.
Run the following:
cd sendmail/ && sh Build && cd ../
Once that has completed (without error, hopefully), we need to build a
config file. The file cf/README has explanations of virtually every
sendmail configuration option available. I would advise you to at least
browse the sections the config below mentions.
cd into the cf/cf/ directory. Edit the file config.mc (it doesn't exist..
we are creating it). The following is the config I use, and it has proven
itself to be quite flexible. I am recommending this config for most. If
you feel you may have special needs, consult the cf/README file.
The following lines belong in the config.mc file you should be editing now.
VERSIONID(`$Id: sendmail.txt,v 1.3 2001/07/01 23:09:20 highos Exp $')
FEATURE(`virtusertable', `hash -o /etc/mail/virtusertable')dnl
define(`confCW_FILE', `-o /etc/mail/sendmail.cw')dnl
This config enables the following features.
* procmail as the local delivery agent.
* No uucp support.
* Virtual user table support.
* Access database support (handles relaying, blacklisting, etc).
Save this file, and run the following command:
sh Build config.cf
mkdir -p /etc/mail /var/spool/mqueue
cp config.cf /etc/mail/sendmail.cf
cp config.mc /etc/mail/
If there were any errors generating the config.cf file, please double check
the config.mc's syntax (check those `' things).
Now, enter the top source directory (should be a cd ../../ away), and run
sh Build install
Sendmail is now installed.. now to finish the configuration.
Edit the /etc/mail/aliases file. Insert (at least) the following lines:
See man 5 aliases for an explanation of this file. It is fairly
Edit the /etc/mail/access file. This file only has to exist.. null content
is OK. This file is quite powerful.. you should read the cf/README section
about it to fully understand it.
These lines are to serve as an example, and are not required in any way.
spammer at aol.com ERROR:"550 I don't like spam, you spammer!"
The first line tells sendmail to relay any request from my LAN, 10.0.0.*.
The second line tells sendmail to reject any mail from spammer at aol.com with
the message, "I don't like spam, you spammer!"
IMPORTANT: The following command MUST BE EXECUTED after ANY changes to the
Now, we must create the access.db (in the form sendmail wants it). The
following command will do so.
makemap hash /etc/mail/access < /etc/mail/access
This is the last step in the sendmail configuration. We will create the
sendmail.cw file, which sendmail uses as a list of domains which will be
treated as 'local'. If I wanted to accept mail for @microsoft.com, I would
insert, on one line, microsoft.com. Here's my sample sendmail.cw file.
Finally, run the following command:
You will need to run this command any time you update your /etc/mail/aliases
file. If something went wrong somewhere, this command should tell you. If
it's output is more than something like:
/etc/mail/aliases: 5 aliases, longest 6 bytes, 62 bytes total
check to see what sendmail said in syslog.
To run sendmail in daemon mode, where it will listen on port 25 and accept
mail, use the following.
/usr/sbin/sendmail -bd -q20m
The -q20m tells sendmail to re-run the mail queue every 20 minutes.
To stop sendmail, use the following:
kill -SIGTERM `head -1 /var/run/sendmail.pid`
Sendmail provides a few useful tools:
Dumps the contents of the mail spool, along with the status of
Shows various usage stats.
Displays current aliases.
Auto-responder of sorts for when you're laying on the beach.
See the corresponding man pages for more information.
Testing your configuration
The easiest way will be to open an MUA (like mutt), and first attempt to
send a message to "root". If root recieves the message, things should be
ok. Second, send a message to root at some.host.you.listed.in./etc/sendmail.cw.
Do this for each domain you have listed in that file. All mail should go to
There are some more 'advanced' features that are beyond the scope of this.
You should refer to the excellent documentation which comes with the sendmail
source for more information.
* Sendmail takes forever to start! WTF!
Sendmail can't resolve your hostname. In /etc/hosts, you need the
127.0.0.1 hostname.domain.tld hostname
* The hostname and domain sendmail picks up isn't the right one! Any mail
* I send comes from an unresolvable/incorrect domain!
Add the following lines to /etc/mail/sendmail.cf
The Dw<string> defines the hostname, Dm<string> defines the subdomain
name, and the Dj line expands the Dw and the Dm values into the
canonical domain name, which is myhostname.mydomain.tld in the above
The above will force sendmail to act as that host.domain.tld.
Alternatively, you could simply:
which would tell sendmail to 'masquerade' all mail as
Either of these will fix the issue, but the previous is probably the
one you will want to go with. With the latter, sendmail will still
identify itself as the erroneous host.domain.tld.
* Mutt (the *ONLY* MUA!) errors out when I try to send a message!
* Something about an exec error 127! WTF!
Add the following line to either 1) your ~/.muttrc, or 2) the
system-wide Muttrc (mutt's ./configure --prefix/etc/Muttrc).
The latter is the more sensible of the two.
set sendmail = "/usr/sbin/sendmail"
End of hint
More information about the hints