Intro
I guess I’ve ragged on sendmail before. Incredibly powerful program. Finding out how to do that simple thing you want to do may not be so easy, even with the bible at your side. So to that end I’m making an effort to document those simple things which I’ve found I’ve struggled with.
The Details
Today I wanted to capture all email coming into my sendmail daemon. Well, actually it’s a little more complicated. I didn’t want to disturb production email, but I wanted to capture a spam sample. Today there was a hugely effective spam campaign purporting to be email from the Better Business Bureau (BBB). All the emails however actually came from various senders @aicpa.org. Postini put a filter in place but I knew more were getting through. But they weren’t coming to me. How to get capture them without disturbing users?
In this post I gave some obscure but useful tips for sendmail admins, including the ever-useful smarttable add-on. To reprise, smarttable allows you to make delivery decisions based on sender! That’s totally antithetical to your run-of-the-mill sendmail admin, but it’s really useful… Like now. So I quickly put up a sendmail instance, copying a working config I use in production. But I changed the listener to IP address 127.0.0.2 (which I fortunately had already set up for some other reason I can no longer recall). That one’s pretty standard. That’s just:
DAEMON_OPTIONS(`Name=sm-cap, Addr=127.0.0.2')dnl |
Of course you want to create a new queue directory just for the captured emails. I created /mqueue/c0 and put in this line into my .mc file:
define(QUEUE_DIR, `/mqueue/c*')dnl |
And here’s the main point, how to defer delivery of all emails. Sendmail actually distinguishes between defer and queueonly. I chose queueonly thusly:
define(`confDELIVERY_MODE',`queueonly')dnl |
If by chance you happen to misspell DELIVERY_MODE, like, let’s say, DELIERY_MODE, you don’t seem to get a whole lot of errors. Not that that would ever happen to us, mind you, I’m just saying. That’s why it’s good to also know about the command-line option. Keep reading for that.
It’s simple enough to test once you have it running (which I do with this line: sudo sendmail -bd -q -C/etc/mail/capture.cf).
> telnet 127.0.0.2 25
Trying 127.0.0.2…
Connected to 127.0.0.2.
Escape character is ‘^]’.
220 drj.com ESMTP server ready at Fri, 24 Feb 2012 15:16:40 -0500
helo localhost
250 drjemgw2.drj.com Hello [127.0.0.2], pleased to meet you
mail from: [email protected]
250 2.1.0 [email protected]… Sender ok
rcpt to: [email protected]
250 2.1.5 [email protected]… Recipient ok
data
354 Enter mail, end with “.” on a line by itself
subject: test of the capture-only sendmail instance
Just a test!
-Dr J
.
250 2.0.0 q1OKGet2008636 Message accepted for delivery
quit
221 2.0.0 drj.com closing connection
Connection closed by foreign host.
Is the message there, queued up the way we’d like? You bet:
> ls -l /mqueue/c0
total 16 -rw------- 1 root root 19 2012-02-24 15:17 dfq1OKGet2008636 -rw------- 1 root root 542 2012-02-24 15:17 qfq1OKGet2008636 |
There also seems to be a second way to run sendmail in queue-only fashion. I got it to work from the command-line like this:
> sudo sendmail -odqueueonly -bd -C/etc/mail/capture.cf
The book says this is deprecrated usage, however. But let’s see, that’s O’Reilly’s Sendmail 3rd edition, published in 2003, we’re in 2012, so, hmm, they still haven’t cut us off…
One last thing, that smarttable entry for my main sendmail daemon. I added the line:
@aicpa.org relay:[127.0.0.2]
Conclusion
It can be useful to queue all incoming emails for various reasons. It’s a little hard to find out how to do this precisely. We found a way to do this without stopping/starting our main sendmail process. This post shows a couple ways to do it, and why you might need to.
May 2012 Update
Just wanted to mention about BBB email how I handle it now. They told me they maintain an accurate SPF record. Sure enough, they do. Now we only accept bbb.org email when the SPF record is a match. But I don’t use sendmail for that, I use Postini’s (OK, Google’s, technically) mail hygiene service. Postini rocks!
My most recent post on how to tame the confounding sendmail log is here.
4 replies on “How to run sendmail in queue-only mode”
Hi, thanks, I was looking about this option as I have to move mailboxes between two partitions and I don’t want NDR to be generated.
Then I changed /etc/init.d/sendmail
from: daemon /usr/sbin/sendmail $([ “x$DAEMON” = xyes ] && echo -bd )
to: daemon /usr/sbin/sendmail $([ “x$DAEMON” = xyes ] && echo -bd -odqueueonly)
and works on a RH 8.12 and 8.13
As I had also to wait for mail data trasfer I set also in /etc/sysconfig/sendmail
QUEUE= 3h
bye,
leo.
Are you putting the DAEMON_OPTIONS in a config file somewhere or are you running that cmd directly from terminal? Also does queueonly mode generate NDRs and are those files in queue locked after they arrive?
Yes, of course, DAEMON_OPTIONS is one line of many in my MC config file. That’s the proper, sendmail, way to do things. It’s kind of sendmail 101. Get the O’Reilly book Sendmail by Bryan Costales if you are unfamiliar with that.
queueonly mode does not generate NDRs.
I would say the messages in that directory do not appear locked, but I’m sort of taking an educated guess on that.
[…] Tip 4: How to send the same email to two (or more) different servers Someone claimed to need this unusual feature. See the discussion in the comment section about how I believe this is possible to do and an outline of how I would do it. The blog posting I reference about running sendmail in queue-only mode is here. […]