Results 1 to 9 of 9
I am trying to find a way to execute a .php file shortly after an email has been received and placed into a specific user's mailbox. I do not need ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-10-2010 #1Just Joined!
- Join Date
- Nov 2009
- Posts
- 14
Execute Script Email
I am trying to find a way to execute a .php file shortly after an email has been received and placed into a specific user's mailbox. I do not need to pipe the email to the php file, I just want the php file to be executed. Currently, I have setup my email server using this guide as a reference (I am running Lenny, not etch, used this as a guide): h_t_t_p://workaround.org/ispmail/etch
Thanks in advance!
noop
- 02-12-2010 #2
is the mail stored on the system as well as the php page? i use virtual directories on mine
you could also throw in something to remove the message, if you weren't actually gonna read it.Code:#!/bin/bash directory=/var/mail/blah/user/new/ if [ "$(ls -A $directory)" ]; then wget http://www.yourserver.com/my.php fi
linux user # 503963
- 02-13-2010 #3Just Joined!
- Join Date
- Nov 2009
- Posts
- 14
Yes the mail is stored on the system as well as the php script.
I also have virtual users/mail setup.
Here is the path to each user's mailbox on my server (domain and use name replaced with actual values from a mySQL database):
/home/vmail/domain.com/username/Maildir
Where are you placing that script and how would I set that up to check for a specific user?
Thank you for helping scathefire,
noop
- 02-15-2010 #4
If its only one one user, just substitute my directory variable in the example to whatever suits you. You should have a 'new' and 'cur' directory within your Maildir, unless its all being stored in MBOX format.
The script can be placed anywhere. Mine is actually fired off in cron, so I drop this inside /etc/crontab
Code:*/1 * * * * root /some/place/mail-check.sh
linux user # 503963
- 02-17-2010 #5Just Joined!
- Join Date
- Nov 2009
- Posts
- 14
Thank you for the help scathefire! I have it working using a cron setup, however do you know much about email piping?
- 02-17-2010 #6
i've had more luck getting mail piping to work with qmail that postfix. Most of the time its hit and miss, but in the past I would do the following:
inside of master.cf add a line that would be something like:
those ${} are variables that postfix knows, usually like original_recipient or something. Not required if you don't need them of course. You can define your own variables as well, like --username or -p or whatever you want to pass to your script.Code:myscript unix - n n - - pipe user = postfix argv=/path/to/script ${some arguement} ${another arguement}
You have to add a file, if you don't have it called transport inside /etc/postfix, and the following line:
Make sure that postfix is setup to look for said file as well:Code:my.email.address@my.domain.com myscript
Restart mailman and you should theoretically be good to go, check your maillog for errors. You may have to play around with ownerships and permissions to get it right. Like I said, doing it in qmail is much easier, but qmail is dated from what I can tell (its no longer maintained anyways).Code:main.cf ... transport_maps = hash:/etc/postfix/transport
linux user # 503963
- 02-21-2010 #7Just Joined!
- Join Date
- Nov 2009
- Posts
- 14
When I do that, I receive this:
If I rename the transport file to transport.db then I receive:Feb 20 22:33:15 sandbox postfix/trivial-rewrite[1428]: fatal: open database /etc/postfix/transport.db: No such file or directory
Feb 20 22:33:16 sandbox postfix/master[1384]: warning: process /usr/lib/postfix/trivial-rewrite pid 1428 exit status 1
Feb 20 22:33:16 sandbox postfix/master[1384]: warning: /usr/lib/postfix/trivial-rewrite: bad command startup -- throttling
Here is my master.cf file:Feb 20 22:42:26 sandbox postfix/master[1702]: daemon started -- version 2.5.5, configuration /etc/postfix
Feb 20 22:42:26 sandbox postfix/qmgr[1705]: 072D5EC090: from=<myemail@mydomain.com>, size=1456, nrcpt=1 (queue active)
Feb 20 22:42:26 sandbox postfix/trivial-rewrite[1707]: fatal: open database /etc/postfix/transport.db: Invalid argument
Feb 20 22:42:27 sandbox postfix/master[1702]: warning: process /usr/lib/postfix/trivial-rewrite pid 1707 exit status 1
Feb 20 22:42:27 sandbox postfix/master[1702]: warning: /usr/lib/postfix/trivial-rewrite: bad command startup -- throttling
Currently, I am not sending any arguments to the script, I am just trying to get it to execute. I have given the script executive privileges.# maildrop. See the Postfix MAILDROP_README file for details.
# Also specify in main.cf: maildrop_destination_recipient_limit=1
#
maildrop unix - n n - - pipe
flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
myscript unix - n n - - pipe
user=vmail argv=/var/script/test.php
Thanks helping,
noop
- 02-21-2010 #8
you need to run
from the /etc/postfix directory everytime you edit that transport file, it has to rebuild that berkley db file.Code:postmap transport
linux user # 503963
- 02-24-2010 #9Just Joined!
- Join Date
- Nov 2009
- Posts
- 14
Hurray! It works!!!! Thank you very much!!!


Reply With Quote
