Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Dec 2002 14:06:10 +0000
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        FreeBSD Questions <freebsd-questions@FreeBSD.ORG>
Subject:   Re: Getting Perl scripts to work as mail filters
Message-ID:  <20021218140610.GB74300@happy-idiot-talk.infracaninophi>
In-Reply-To: <OE26RvITt7Qs6hvfPAZ000066b0@hotmail.com>
References:  <OE26RvITt7Qs6hvfPAZ000066b0@hotmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Dec 18, 2002 at 02:46:14PM +0100, Mxsmanic wrote:

> What do I have to do to make a simple Perl script filter incoming mail for a
> mailbox?  I wrote a script that just reads standard input and writes it to
> standard output, then put it in my home directory, then changes
> /etc/mail/aliases to point to it, like this:
> 
> mymail:    "|/usr/home/mymail/perlfilter"
> 
> But when I actually send mail to this address, it just disappears--no error
> message, nothing.  When I execute the same program by hand, it works fine.
> If I remove the alias, the mail is delivered just fine, too.  What am I
> missing??  The Perl program has 755 for permissions and has mymail:users as
> its userid and group.  The first line points to the location of Perl in the
> usual way.  I am at a loss for ideas as to why this isn't working.  The
> sendmail manual seems to indicate that it just pipes the e-mail message into
> this script, then delivers whatever comes out of standard output, but it
> doesn't seem to work.

I believe that sendmail will consider the e-mail to have been
delivered if it can pipe it into your script and the script returns a
successful exit code.  It won't treat the script as a filter: that is,
it won't read the script's output and treat that as a message to
deliver.  Anything your script writes to stdout will be silently
discarded.

If you want that re-mailing effect then you're going to have to make
the script fire up another instance of sendmail, and pipe the output
message from the perl script into sendmail yourself.  Beware of mail
loops though --- make sure you modify the 'To:' header of the message
as it passes through the filter sufficiently that it doesn't hit the
alias expansion again.  Alternatively, take a look at procmail(8)
which can be used to pass a message through a filter program and then
re-send it to a new address.

	Cheers,

	Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
                                                      Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021218140610.GB74300>