Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to filter email using a php script, what I want to do is process the email into a database when it matches a set of rules.

The rules are going to be made using an array of PHP strings and either use str_replace or preg_replace.

I found this tutorial, however when I run this, the mailserver can only accept email, but I cannot login and check my mail anymore, I think the script is gobbling everything up and effectively black holes the server, so it's a partial solution, but not complete.

http://blog.thecodingmachine.com/content/triggering-php-script-when-your-postfix-server-receives-mail

The stage I'm up to is that I can execute the script, it runs and writes to the database when required, but then the email doesn't arrive into the inbox, but also nobody can login to check email either, so I think the script blocks the execution of anything except receiving email and quitting immediately, so it's not useful with a real email server that just wants to filter/clone emails into a database according to a rule engine.

Now either I'm writing the wrong kind of filter, or I'm missing something which allows the email to continue to the inbox it should have been put into, if the script was disabled. I suppose thats the part I'm missing out.

Please Note: The script has to be run using PHP, so alternative solutions are not wanted. I already know about the link: www.postfix.org/FILTER_README.html and I have read it, however I don't know how to translate this into an actual working PHP script. seems I always get stuck at some point, so I'm also not interested in people who give me that link and say I should read it.

The reason I say that is because I've read a lot of questions here which typically end with that link, or an alternative solution, neither of these are helpful, so if your answer is one of those, please don't reply, I am not interested unless you want to help me with my specific problem and I don't want to waste your time.

share|improve this question

4 Answers 4

up vote 2 down vote accepted

Rather than go through all the issues I have with the article you've referenced, I'll skip to the chase.

Use procmail as the delivery agent.

It's a very powerful language which allows you to do all sorts of things, not least copy emails to a mailbox and pipe them through scripts (including PHP - you just read from stdin, write to stdout).

It's not hard to setup, and it makes tasks like this easy. But you might want to get Martin McCarthy' book on procmail if you expect to be building complex systems around this.

share|improve this answer
    
Hi, thanks for your help, it looks exactly like the answer I wanted –  Christopher Thomas Jul 24 '12 at 8:55

Apart from the fact that coding is --> thataway (at Stack Overflow), um... no.

Postfix is UNBELIEVABLY well-documented; please refer to the following resources for attaching external programs to it:

MAIL DELIVERY overview

LOCAL DELIVERY manual, section "EXTERNAL COMMAND DELIVERY"

PIPE DELIVERY manual - the postfix Swiss-army knife of Doom.

Happy 'fixin' !

share|improve this answer
    
sorry, but I clearly stated I didnt want these kinds of answers, lucky I don't have 125 points –  Christopher Thomas Jul 24 '12 at 8:54
    
Postfix is a complex piece of software, and e-mail is decidedly not for beginners. If you desire this and are unwilling to learn, then you pay. A professional. –  adaptr Jul 24 '12 at 8:57
    
I am a professional. Plus email is not complex. Just the manuals are written for robots and not humans. –  Christopher Thomas Jul 24 '12 at 9:00
    
An excellent argument why you should pay for professional support! –  adaptr Jul 24 '12 at 9:06
    
thank you for the continued discussion, but I already have the correct answer above, to use procmail. as I mentioned before, "RTFM" responses are not wanted. I thought I'd made that point quite clear. –  Christopher Thomas Jul 24 '12 at 9:10

You keep getting pointed to FILTER_README because it contains your answer. You may have read it, but not understood it.

The tutorial that you linked intentionally prevents messages from being delivered (and it even says so).

In order to deliver a message from a filter, you must redeliver it to Postfix by calling the sendmail(8) command. This is clearly documented in the FILTER_README and the sample script there even shows it being done.

share|improve this answer

http://moshez.blogspot.co.il/2013/02/techpostfix-mail-server-filter-email-by.html Howto: create PHP script to filter incoming email on POSTFIX MAIL SERVER

share|improve this answer
2  
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. –  Michael Hampton Feb 21 '13 at 8:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.