Q: Why is sendmail timing out to my local mailhost?

Q: Why do I get "connection timed out" messages while trying to connect to my local mailhost.  When I log in to the mailhost, it seems lightly loaded?

Q: Why is mail taking so long to deliver locally?

A: There are probably several possible answers to these questions.  Here is one of them.

Mail gets queued up in /usr/spool/mqueue using two different files for each piece of mail.  One file is the header information for the mail, and the other file is the body of the message.  The directory /usr/spool/mqueue, like all directories, is simply a file that contains a listing of filenames and their associated inodes that are contained in the directory.  The size of a directory is usually around 1 or 2 kilobytes.  The more files you have in a directory and the longer the names of the files, the larger the size of the directory file is.  The size of the directory file never decreases.

Whenever a file is created the system must open up the directory file and write some information into it.  The larger the directory file is, the longer it takes to read through it and add the new entry.  The same thing is true for deleting files.

If you have a mail server that deals with a lot of traffic and something causes the mail to get backed up in the queue, the directory file can grow very large (50+ KB) storing the names of the backed up mail.  Even after clearing the entire queue, the size of the directory file remains the same, and creating and destroying files in that directory starts taking a significant amount of time.  In fact, the mail server can become so slow that connections to it start timing out even though the machine seems to be very responsive.

The only solution is to create a new mqueue directory:

1. Find the incoming sendmail process and kill it.

	% ps auxw | grep sendmail
	root       206   0.0  0.8 1.55M  312K ?  S     0:04 -accepting connections 	(sendmail)
	% kill <PID>	# PID is 206 in the above example
	
2. Wait for the outgoing sendmail processes to finish.

	% ps auxw | grep sendmail

You can keep running the above command until all of the outgoing sendmail processes have died or you can go ahead and kill them all.  Sendmail should be tolerant of getting killed.

3. Move /usr/spool/mqueue to /usr/spool/mqueue.old and create a new mqueue

	% cd /usr/spool
	% mv mqueue mqueue.old
	% mkdir mqueue

5. Move all of the files from mqueue.old into the new mqueue directory

	% mv mqueue.old/*  mqueue

6. Remove old mqueue directory

	% rmdir mqueue.old

6. Restart sendmail

	% /usr/lib/sendmail -bd -q30m

QA876

Valid for 1.0, 2.0, 3.0