procmail
[Top] [All Lists]

Re: procmail and text file

2000-01-15 03:36:24
On Fri, 14 Jan 2000 09:11:43 -0600 (CST), tomcat(_at_)visi(_dot_)com wrote:
I have a web page that fires off an email to procmail.
I want procmail to look at the subject line (which
I write in my perl script that sends the email) and
send off email to everybody listed in a emmail_list.txt
file.  The emmail_list.txt file is not in the same
directory as my .procmailrc file.
Can anybody suggest the syntax for getting sendmail
together with this file?

The simple solution is of course the well-known

    :0
    * whatever conditions
    ! `cat /path/to/emmail_list.txt`

but it won't work if the file is too big for the shell to fit on a
single command line. (See <http://www.iki.fi/era/unix/arg-max.html>
for a discussion.) So you might want to split the list of recipients
somehow.

I don't want somebody else to host this list for me,
as some might suggest.  This is not spam, its for
a large soccer club.

As you seem to be correctly inferring, a proper mailing list package
will have the means to take care of this for you. And you don't need
"somebody else" to host the list -- a good ISP will let you install
and run your own mailing list. But seeing as you were specifically
asking for how to do this the hard and bothersome way, here we go.

First attempt:

    :0
    * whatever conditions
    {

        TEMPFILE=/tmp/$$.femptile
        TRAP="rm -f $TEMPFILE"
        :0c
        $TEMPFILE

        :0i
        | while read recipient; do \
                sendmail -oi "$recipient" <$TEMPFILE; \
            done </path/to/emmail_list.txt
        # is the double m in "emmail" significant?
    }

Yes, `banner ugh`. Apart from the unattractive use of a temporary
file, this will send each recipient's message separately. This is not
very popular among mail administrators. Specifically, this is one of
the things that is a bit hard to do right if you insist on rolling
your own.

A better approach might be something like this:

    :0
    * whatever conditions
    | ( sed -e 's/^/Bcc: /' </path/to/emmail_list.txt ; \
        formail -I "To: /dev/null Soccer List <nobody>" \
                -I Cc: -I Bcc: -I Resent- ) \
      | $SENDMAIL -oi -t

This will add your entire list of recipients as Bcc: headers, zap any
original To:, Cc:, Bcc:, and Resent- headers, and pass it all to
Sendmail.

The To: header is a bogus one. It's there because there has to be some
To: header and the "nobody" alias is frequently set up as a standard
way to send stuff directly to /dev/null via Sendmail. Another way to
avoid putting anything real there is to use RFC822 group syntax -- you
see this in spam sometimes, too: To: recipient list not shown:;

You might also want to set From: and/or Reply-To: to the list's
submission address, if there is such an animal.

You would have to be very careful to avoid empty lines or comments in
emmail_list.txt -- or, better, use a better sed script than the simple
one here. The file should contain one recipient per line (or why not a
few comma-separated recipients per line, but there's no real need or
reason to, I would guess).

I don't know whether Sendmail might choke if you push in an insane
amount of Bcc: headers. Real mailing list managers (and real spam
packages ...) send a few recipients at a time, and sort them by
domain, so that all copies for one domain are sent as one physical
message. But I believe that's mainly in order to spread out the load.

man xargs, too.

Caveat utilitor and all that; this is off the top of my head. Still,
hope this helps,

/* era */

-- 
 Too much to say to fit into this .signature anyway: <http://www.iki.fi/era/>
  Fight spam in Europe: <http://www.euro.cauce.org/> * Sign the EU petition

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