smtp-sink

grab all the mail!

I was recently asked if there's such a thing that can act like a mailserver and just save everything that comes in, and send nothing out.

Turns out, Postfix has exactly such a thing, called smtp-sink. This is a small command-line utility that will listen on a port and accept incoming emails and save them to disk.

The following command will listen on port 25 and save each received message to /tmp/sink/year-month-date/hour.<random string>. As an example, one of these incoming messages got saved to /tmp/sink/2023-06-18/09.59c88c77.

root# smtp-sink -d %Y-%m-%d/%H. -h hostname.domain -R /tmp/sink -u nobody -v 25 5

As the manpage proved to be somewhat hard to grok and provides no examples, here's a breakdown of the options I used:

    -d <dump-template>, this defines the dir/filenames in which the messages will be saved. It supports strftime[1] variables like %Y for year, %m for month, %d for day of month, %H for hour, %M for minute etc.
    -h <hostname>, the hostname that will be used in the SMTP replies.
    -R <chroot>, chroot into the given dir.
    -u <user>, switch to the given user. Don't want to run this as root!
    -v, be verbose so I can see what's happening.
    25, listen to port 25.
    5, the max queue length. I chose 5 because my finger was already on the 5 key.

[1] See the strftime manpage for a comprehensive list of available variables.

Important note: if you use netcat or similar to test this thing, please note that it requires each line to be terminated with CRLF. A simple LF won't do. This might be achieved by pressing CTRL-V CTRL-M before hitting enter, but this depends on the software you're using.

Aaaand it didn't take long before one of my old friends dropped me a message!

X-Client-Addr: [redacted]
X-Client-Proto: ESMTP
X-Helo-Args: WIN-CLJ1B0GQ6JP
X-Mail-Args: <spameri@tiscali.it>
X-Rcpt-Args: <spameri@tiscali.it>
Received: from WIN-CLJ1B0GQ6JP ([[redacted]])
	by [redacted] (smtp-sink) with ESMTP id 1b71cd48;
	Fri, 16 Jun 2023 21:20:06 +0000 (UTC)
From: spameri@tiscali.it
Subject: [redacted]
To: spameri@tiscali.it
Date: Fri, 16 Jun 2023 14:20:06 -0700
X-Priority: 3
X-Library: Indy 8.0.25

t_Smtp.LocalIP