Mailfromd |
|
General-Purpose Mail Filter |
Sergey Poznyakoff |
Mailfromd Manual (split by node): | ? |
mtasim
interactive mode mode If you start mtasim
without options, you will see the
following:
220 mtasim (mailfromd 6.0) ready (mtasim) _ |
The first line is an usual RFC 2821 reply. The second one is
a prompt, indicating that mtasim
is in interactive mode and
ready for input. The prompt appears only if the package is compiled
with GNU Readline and mtasim
determines that its standard
input is connected to the terminal. This is called interactive
mode and is intended to save the human user some typing by offering
line editing and history facilities (see (readline)Command Line Editing section `Command Line Editing' in GNU Readline Library). If the package
is compiled without GNU Readline, you will see:
220 mtasim (mailfromd 6.0) ready _ |
where ‘_’ represents the cursor. Whatever the mode,
mtasim
will wait for further input.
The input is expected to consist of valid SMTP commands
and special mtasim
statements. The utility will act exactly
like a RFC 2821-compliant MTA, except that it will
not do actual message delivery or relaying. Try typing HELP
to
get the list of supported commands. You will see something similar
to:
250-mtasim (mailfromd 6.0); supported SMTP commands: 250- EHLO 250- HELO 250- MAIL 250- RCPT 250- DATA 250- HELP 250- QUIT 250- HELP 250 RSET |
You can try a simple SMTP session now:
220 mtasim (mailfromd 6.0) ready (mtasim) ehlo localhost 250-pleased to meet you 250 HELP (mtasim) mail from: <me@localhost> 250 Sender OK (mtasim) rcpt to: <him@domain> 250 Recipient OK (mtasim) data 354 Enter mail, end with `.' on a line by itself (mtasim) . 250 Mail accepted for delivery (mtasim) quit 221 Done |
Notice, that mtasim
does no domain checking, so such thing
as ‘rcpt to: <him@domain>’ was eaten without complaints.
So far so good, but what all this has to do with
mailfromd
? Well, that's what we are going to explain. To
make mtasim
consult any milter, use ‘--port’
(‘-X’) command line option. This option takes a single
argument that specifies the milter port to use. The port can be given
either in the usual Milter format (See milter port specification,
for a short description), or as a full ‘sendmail.cf’ style
X
command, in which case it allows to set timeouts as well:
$ mtasim --port=inet:999@localhost
# This is also valid:
$ mtasim --port='mailfrom, S=inet:999@localhost, F=T, T=C:100m;R:180s'
|
If the milter is actually listening on this port, mtasim
will connect to it and you will get the following initial prompt:
220-mtasim (mailfromd 6.0) ready 220 Connected to milter inet:999@localhost (mtasim) |
Notice, that it makes no difference what implementation is listening
on that port, it may well be some other filter, not necessarily
mailfromd
.
However, let's return to mailfromd
. If you do not want to
connect to an existing mailfromd
instance, but prefer
instead to create a new one and run your tests with it (a preferred
way, if you already have a stable filter running but wish to test a
new script without disturbing it), use ‘--port=auto’. This
option instructs mtasim
to do the following:
mailfromd
. The arguments and
options for that instance may be given in the invocation of
mtasim
after a double-dash marker (‘--’)
When mtasim
exits, it terminates the subsidiary
mailfromd
process and removes the temporary directory it has
created. For example, the following command will start
mailfromd -I. -I../mflib test.rc
:
$ mtasim -Xauto -- -I. -I../mflib test.rc 220-mtasim (mailfromd 6.0) ready 220 Connected to milter unix:/tmp/mtasim-j6tRLC/socket (mtasim) |
The ‘/tmp/mtasim-j6tRLC’ directory and any files within it will
exist as long as mtasim
is running and will be removed when
you exit from it.(25) You can also instruct the subsidiary
mailfromd
to use this directory as its state directory
(see statedir). This is done by ‘--statedir’ command line
option:
$ mtasim -Xauto --statedir -- -I. -I../mflib test.rc |
(notice that ‘--statedir’ is the mtasim
option,
therefore it must appear before ‘--’)
Special care should be taken when using mtasim
from root
account, especially if used with ‘-Xauto’ and
‘--statedir’. The mailfromd
utility executed by it
will switch to privileges of the user given in its configuration
(see section Starting and Stopping) and will not be able to create data in
its state directory, because the latter was created using ‘root’
as owner. To help in this case, mtasim
understands
‘--user’ and ‘--group’ command line options, that have
the same meaning as for mailfromd
.
Now, let's try HELP
command again:
250-mtasim (mailfromd 6.0); supported SMTP commands: 250- EHLO 250- HELO 250- MAIL 250- RCPT 250- DATA 250- HELP 250- QUIT 250- HELP 250- RSET 250-Supported administrative commands: 250- \Dname=value [name=value...] Define Sendmail macros 250- \Ecode Expect given SMTP reply code 250- \L[name] [name...] List macros 250 \Uname [name...] Undefine Sendmail macros |
While the SMTP commands do not need any clarification, some words about the administrative commands are surely in place. These commands allow to define, undefine and list arbitrary Sendmail macros. Each administrative command consists of a backslash followed by a command letter. Just like SMTP ones, administrative commands are case-insensitive. If a command takes arguments, the first argument must follow the command letter without intervening whitespace. Subsequent arguments can be delimited by arbitrary amount of whitespace.
For example, the \D
command defines Sendmail macros:
(mtasim) \Dclient_addr=192.168.10.1 f=sergiusz@localhost i=testmsg (mtasim) |
Notice that mailfromd
does not send any response to the
command, except if there was some syntactic error, in which case it
will return a ‘502’ response.
Now, you can list all available macros:
(mtasim) \L 220-client_addr=192.168.10.1 220-f=sergiusz@localhost 220 i=testmsg (mtasim) |
or just some of them:
(mtasim) \Lclient_addr 220 client_addr=192.168.10.1 (mtasim) |
To undefine a macro, use \U
command:
(mtasim) \Ui (mtasim) \l 220-client_addr=192.168.10.1 220 f=sergiusz@localhost (mtasim) |
Now, let's try a real-life example. Suppose you wish to test the
greylisting functionality of the filter script described in Example of a Filter Script File. To do this, you start mtasim
:
$ mtasim -Xauto -- -I. -I../mflib test.rc 220-mtasim (mailfromd 6.0) ready 220 Connected to milter unix:/tmp/mtasim-ak3DEc/socket (mtasim) |
The script in ‘test.rc’ needs to know client_addr
macro,
so you supply it to mtasim
:
(mtasim) \Dclient_addr=10.10.1.13 |
Now, you try an SMTP session:
(mtasim) ehlo yahoo.com 250-pleased to meet you 250 HELP (mtasim) mail from: <gray@yahoo.com> 250 Sender OK (mtasim) rcpt to: <gray@localhost> 450 4.7.0 You are greylisted for 300 seconds |
OK, this shows that the greylisting works. Now quit the session:
(mtasim) quit 221 Done |
However, this is true only if the program
is exited the usual way (via QUIT
or end-of-file). If it is
aborted with a signal like SIGINTR
, the temporary directory is
not removed.
Mailfromd Manual (split by node): | ? |
Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.