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.
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:
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:
And here’s the main point, how to defer delivery of all emails. Sendmail actually distinguishes between defer and queueonly. I chose queueonly thusly:
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
Connected to 127.0.0.2.
Escape character is ‘^]’.
220 drj.com ESMTP server ready at Fri, 24 Feb 2012 15:16:40 -0500
250 drjemgw2.drj.com Hello [127.0.0.2], pleased to meet you
mail from: email@example.com
250 2.1.0 firstname.lastname@example.org… Sender ok
rcpt to: email@example.com
250 2.1.5 firstname.lastname@example.org… Recipient ok
354 Enter mail, end with “.” on a line by itself
subject: test of the capture-only sendmail instance
Just a test!
250 2.0.0 q1OKGet2008636 Message accepted for delivery
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:
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!