Postfix – Forward All Mail on a Specified Domain to Script

emailpipepostfixUbuntu

I run a disposable e-mail service that accepts all incoming mail and forwards it to a PHP script that stores it in a database for people to view. Before now, I have been on shared hosting with cPanel, which makes it easy to pipe e-mails to a script. Now, however, I got my own VPS, and it doesn't have cPanel. How do I pipe e-mails to script? Further, how do I pipe emails to any address on certain specified domains to my script? You see, aside from the main domain, there are several alternate domains that people can use if the main domain is blocked, and on each domain I want any address to be usable (xyz@domain1, abc@domain2, anythingelse@domain3).

The VPS has Ubuntu 9.04 installed, and I have been experimenting with Postfix, though I can switch to Exim or Sendmail if it is easier.

Best Answer

Figured it out at last. I used Sendmail in the end. I turned on the virtusertable feature in sendmail.mc, (see the info on the Sendmail Website), then put in /etc/mail/virtusertable the following line:

@disposaldomain.net parser@localhost

Which pipes all mail to that domain to the user "parser". Then, I put in at the end of /etc/mail/aliases this line:

parser: "|/path/to/script/parser.php"

After that, I had to run these commands (from /etc/mail):

makemap hash virtusertable.db < virtusertable
newaliases
/etc/init.d/sendmail reload
/etc/init.d/sendmail restart

That did it!