[Gllug] Using sendmail to execute PHP scripts

Mike Brodbelt mike at coruscant.demon.co.uk
Thu May 1 19:21:02 UTC 2003


On Thu, 2003-05-01 at 08:55, Peter Adamson wrote:

> I've got a nice little php script from somwhere (can't remember where)
> which takes emails via a pipe, stripes out attachments and puts the
> message along with some header info into a mySQL database.
> 
> The problem I'm having is getting sendmail to actually execute the
> script when an email comes in from a specific user.
> 
> /etc/aliases has:
> #This is a test account for the email-mysql gateway
> test_support: "| php /home/peter/bin/gateway.php"
> 
> To make sure security isn't an issue I've been naughty:
> #Mprog,         P=/usr/sbin/smrsh, F=lsDFMoqeu9, S=10/30, R=20/40,
> D=$z:/,
> #               T=X-Unix,
> #               A=sh -c $u
> 
> Mprog,         P=/usr/sh

Gaaah. Horror abounds.

The way I would do this is:-

Create a class, populated from a file, that will contain all the email
addresses you want handed off to the mysql database. You can do this
with some stuff like this at the bottom of your sendmail.mc file:-

LOCAL_CONFIG
# file listing aliases for MySQL delivery
F{MySQL}/etc/mail/mysql-aliases

Then, you can add a "mysql" mailer, with its P set to your php script:-

Mdatabase,      P=/usr/local/bin/php, F=DFMSPhnu9, S=EnvFromSMTP/HdrFromSMTP,
		R=EnvToSMTP/HdrFromSMTP,
                A=php $h $f $u /home/peter/bin/gateway.php


Lastly, a change in LOCAL_RULE_0 will be needed so that anything in the
MySQL class will get delivered via the database mailer.

Make all the necessary changes in your mc file, and regenerate the cf.
Then, whenever you want to add an alias for database delivery, you just
need to dump the address in the /etc/mail/mysql-aliases file. You can
give access to that file to database type admin people without opening
up the whole mail system if you like.

Caveat: the above is from memory and plagiarised from the Mprocmail
define - don't just copy it verbatim. You will need to take a little
time making sure the mailer does what you expect.

Doing it this way gets you lots of flexibility in what you can pass to
the mailer program, as you have all the information to hand that
sendmail has about the message.

HTH,

Mike.



-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list