I am using postfix for my linux mail server. The goal is to have any incoming mail dumped into a database with the headers and message information, then the e-mail being deleted from the mail server. Is there any way to make postfix post a message to a php file everytime a new e-mail comes in then delete the e-mail message? The only other way I can see to make a script to poll the e-mail server, read each mail and transfer the contents to a database, then delete the messages from the mail server. Being able to have postfix automatically execute the php script for all new incoming mails would be a better choice. If it makes a difference, the mail server and the server with the php file is the same. Any direction in this matter would be greatly appreciated.
A:
use .forward, /etc/aliases, hashtable etc to forward mail to a script.
In /etc/aliases, I have
mysite-confirm: |/home/mysite/confirm.sh
In confirm.sh, I have
#!/bin/sh
basedir=/home/mysite/www
php -d include_path=$basedir/includes -f $basedir/cli/confirm.php
In confirm.php, the magic happens:
$contents = file_get_contents("php://stdin");
do_magic_with_mail($contents);
All quite simple and rigid. The only downside is that you could mail mysite-confirm@any_domain_I_host.com, but you can fix that with the right aliases / virtualmaps etc.
mvds
2010-07-15 18:41:06
What is do_magic_with_mail()? Doesn't appear to be listed as a function on php.net
naif
2010-07-15 19:09:35
The `do_magic_with_mail()` is just you implementing your INSERT query to the database.
Wrikken
2010-07-15 19:25:39
oh yes, sorry I didn't spell that one out... you have your mail in `$contents`, think you can handle it from there?
mvds
2010-07-15 19:41:45
I appreciate the suggestions thusfar, but can't seem to get it to work :/ I'm not that great with mail servers, but I'm working on it. Since the script is being called through cli, I can't tell if the script is even executing, if the message is being read improperly, or if it's not being written to the database properly.I wish there was just a way to configure the server to automatically dump messages to a database, but that just seems like wishful thinking at this point.
naif
2010-07-15 20:14:49
maybe you need to do a `chmod 755 confirm.sh` so the mail server can execute the script. Then, try `file_put_contents("/tmp/maildump",$contents);` in the php script and see what happens. Furthermore, check any logfile you can get your hands on, maillogs in particular. If you don't have the slightest clue where to start, just do `tail -n 20 /var/log/* /var/log/*/* |less` and look for something interesting.
mvds
2010-07-15 21:05:21
and be sure you have commandline php (php-cli) installed. Oh, and try to use /dev/brain
mvds
2010-07-15 21:06:45