sendmail hint update

J. Jones jjones at
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 --------------

TITLE:		Sendmail
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):
		I recommend the latest 8.11 (8.11.4 at this time).

		This will be used as our local delivery agent.

	Berkeley DB:
		Sendmail uses this (libdb) to store much of it's configuration.
		Use the latest 3.* version (3.2.9 currently).

Building the required packages

Berkeley DB:
	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
	the following:

		touch /usr/sbin/sendmail
		make install-suid

	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 (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 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/')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
		mkdir -p /etc/mail /var/spool/mqueue
		cp /etc/mail/
		cp /etc/mail/

	If there were any errors generating the file, please double check
	the's syntax (check those `' things).

	Now, enter the top source directory (should be a cd ../../ away), and run
	the following:

		sh Build
		sh Build install

	Sendmail is now installed.. now to finish the configuration.

	Edit the /etc/mail/aliases file.  Insert (at least) the following lines:

		postmaster: root

	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.

		10.0.0 RELAY
		spammer at 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 with
	the message, "I don't like spam, you spammer!"

	IMPORTANT:  The following command MUST BE EXECUTED after ANY changes to the
	            /etc/mail/access file.

	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 file, which sendmail uses as a list of domains which will be
	treated as 'local'.  If I wanted to accept mail for, I would
	insert, on one line,  Here's my sample 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.

Running sendmail

	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 provides a few useful tools:

			Dumps the contents of the mail spool, along with the status of
			each message.

			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
	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.

Common Problems

	* Sendmail takes forever to start! WTF!

		Sendmail can't resolve your hostname.  In /etc/hosts, you need the
		following: 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/


		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"

		Restart mutt.

End of hint

More information about the hints mailing list