Call PHP script in Postfix

Hi All,

I've used the following guide http://library.linode.com/email/postfix … -fedora-13">http://library.linode.com/email/postfix/postfix-courier-mysql-fedora-13 to setup email on my new Linode and all is working well, on my last host I was able to deliver email to a specific address which could then call a PHP script, I think this was in Qmail before but now I am using Postfic.

I've tried adding a rule to the aliases file as detailed here http://jeroensmeets.net/setup-postfix-t … il-to-php/">http://jeroensmeets.net/setup-postfix-to-forward-incoming-email-to-php/ however this does not work, I expect because the mail is handled by a virtual users table in MySQL, I also tried adding the rule to the MySQL forwarding table with no success, any ideas?

4 Replies

Personally, I'd suggest a cron + imap (passive) solution, ie. your script check the email via imap every X seconds or minutes, then acts upon it if new are found.

Why? Scales better, you can move to different config/mailserver/cluster with NO code changes (just imap connection params, if even that), plus you have better control over incoming and possibly outgoing messages that way, and such standardized code is then available for future use in different conditions.

Thanks Azathoth, was never too keen on the IMAP/Cron method as the script needed activated immediately although I found a solution on this forum (I should have searched properly before posting) http://www.linode.com/forums/viewtopic.php?p=28034

Basically, I created forward in my database which forwards an email address to a local user account, then setup the aliases file to point the local account to the PHP script, works perfectly.

I second the IMAP suggestion, specially if the PHP implementation supports IDLE. You can leave the script running and it will get notification when a new message arrives.

To answer you original question, I got mine to work by first adding an alias from the virtual domain to a local user: example@virtualdomain.com -> localuser (no domain on this one), and then adding the localuser to the /etc/aliases file. I should mention I don't use the MySQL backend, just flat files.

Hope that makes sense, let me know otherwise.

edit: Haha, should remember to refresh before replying.

edit2: Heh, and now I realize you figured it out from a reply I had given someone else here. I had forgotten about that. Good times.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct