procmail
[Top] [All Lists]

Procmail for all outgoing mail - howto

1996-07-19 09:24:12
Jeff Gustafson writes:

     I tried to put in the 2 rules in the procmail man page into 
ruleset 0 of my sendmail.cf.  But I very much doubt that I did that 
correctly.  Here's my .mc file:
...

Maybe you're not sending out with the right address to fire those rules,
or more likely you put them in the wrong place.

Here's a fairly minimal .mc file that works (I used the 8.7.3 cf's),
not really different from yours (assuming you put in the LOCAL_RULE_0,
or else added it to the .cf file *in the right place*).

You can't just stick those rules in ruleset 0, at least
not at the beginning, as the address won't be in the right
"user<@some.host>foo" format.  Best to use LOCAL_RULE_0 and let m4 do
its magic, since you don't want to modify the .cf everytime.

And then most importantly, use -bt to test the correctness
before deployment.

------
include(`../m4/cf.m4')

OSTYPE(linux)

FEATURE(nouucp)
FEATURE(local_procmail)

MAILER(local)
MAILER(smtp)
MAILER(procmail)

LOCAL_RULE_0
# test procmail w/ special '*.proc' virtual domain
R$*<@$*.proc>$*         $#procmail $@/etc/procmailrcs/some.rc $:$1(_at_)$2 $3
# also run it for 'virtual user'
Rspecialuser<@$*>$*     $#procmail $@/etc/procmailrcs/some.rc $:$1 $2
R$*<@$*.procmail>$*     $1<@$2>$3       Already filtered, map back
-----

these additional rules are not changed much from the man page;
a little different on the LHS, a little different on the RHS,
you should understand the differences.


Call this file 'newconfig.mc'.

compile it:
  m4 newconfig.mc > newconfig.cf
now test it:
check ruleset 98, where LOCAL_RULE_0 gets put:
  echo '98 user<@usual.com.proc>foo' | sendmail -bt -C procout.cf 

test through normal invocation
  echo 0,3 user(_at_)normal(_dot_)com(_dot_)proc | sendmail -bt -C newconfig.cf
  echo 0,3 specialuser(_at_)usual(_dot_)com | sendmail -bt -C newconfig.cf


this will show you how sendmail is going to rewrite the address
and where the final destination will be.  The truly paranoid will
put in all possibly address forms, save the output to a file,
and then diff it against different configs to ensure proper functioning
in all cases.

Once you are satisfied with the results of -bt output,
test actual sending using this config file:

 echo procmail for outgoing | sendmail -v -C newconfig.cf 
user(_at_)address(_dot_)proc

or, for more headers:
(echo From: me; echo Subject: foo; echo To: 
user(_at_)test(_dot_)com(_dot_)proc; echo; date)\
 | sendmail -C newconfig.cf user(_at_)test(_dot_)com(_dot_)proc

You will probably need to be root to do this.
The '-v' is optional.

To get the arguments that sendmail is calling procmail with (the
envelope info), a filter-rule like this in your procmail rc file is
useful:

:0 hf
| formail -A "X-envelope-info: 0=$0, 1=$1, 2=$2, 3=$3, 4=$4"

3 & 4 are generally blank; i've only seen them filled in when I have
a mailertable entry sending all of a domain to a procmail file and
there are multiple addresses specified.

I think you should be able to do the rewrites you want pretty easily
within the procmailrc file.


If all has gone well this far, then you can play with changing the various
forms of outgoing addresses that get passed through procmail, and
then when confident make it your config file for production.


Stephen R. van den Berg writes:

Not easy to explain.  If the hint in the procmail man page is not enough,
then the learning curve is too steep for most people to handle (at least,
that's what experience shows).  It would take a *very* lengthy tutorial
to make it easy to setup for anyone.  And even then, it cannot be made
entirely foolproof, due to the flexible configurability of sendmail.

Feel free to consider this a not-so-lengthy semi-tutorial how-to,
and distribute with the docs, if you wish (it took me only 5 minutes
for the sendmail config, but it took me an hour to write this message).


I agree with Stephen:  sendmail config hacking is not for the foolhardy,
faint of heart, or anyone not prepared to take responsibility for
lost or mangled mail.  If you haven't understood everything in this
mail, you should look it up in the documentation.  It is implied that
you have the right set of files and run things in the right places.
It seemed to work for me but I make no warranty for you.

 -todd

<Prev in Thread] Current Thread [Next in Thread>