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

I want to parse and insert some information from the mail that just arrived in a mission critical application's mail server.

I there any way to configure my mail server so that it run a script when mail arrives.

Although I have a debian system but any generic solution (Linux) will do.

share|improve this question
    
possible duplicate of Processing incoming emails with Python –  Ignacio Vazquez-Abrams Apr 19 '11 at 7:40
    
nope no duplicate –  dmourati Apr 19 '11 at 8:27
    
@dmourati: Yes it is. –  Ignacio Vazquez-Abrams Apr 19 '11 at 9:41
1  
What if he's not using postfix or python? –  dmourati Apr 19 '11 at 22:49
    
Found my answer @ www.evolt.org/incoming_mail_and_php –  Rahul Prasad Apr 27 '11 at 9:15

3 Answers 3

up vote 7 down vote accepted

Looks like someone else has already answered this but thought I'd put down a specific answer for you.

I would use procmail and use a recipe in your .procmailrc similar to this:

#turn this off when you're finished testing :)
VERBOSE=on
LOGFILE=/home/user/procmail.log

:0 c #the c means continue on after this recipe is parsed
| /path/to/your/script

You'll also need a default recipe at the bottom to direct the mail into your maildir.

share|improve this answer
    
+1 procmail Edit your .forward and add to taste. Start here pm-doc.sourceforge.net/doc –  dmourati Apr 19 '11 at 8:26
    
+1 - the right solution, procmail gives a lot more flexibility than calling your script directly via .forward, although I'd recomend configuring postfix to use procmail as the MDA rather than chaining from the bundled MDA - e.g. wiki.kartbuilding.net/index.php/Procmail_-_setup_with_postfix –  symcbean Apr 19 '11 at 11:38

Here's a good howto on incoming mail processing. The simplese thing to do is to use the .forward mechanism as described, to pipe a message through a script. Create a mode 600 .forward file in the user's home directory and put a pipe to a script in it:

"|$HOME/bin/your.program -and some arguments" 

However, you should look at using procmail instead, as that howto details. Procmail gives you a lot of advantages, such as more sophisticated logging and mail processing. Here's a simple .procmailrc example (again from that same howto):

:0
* !^FROM_DAEMON
* !^FROM_MAILER
* !^X-Loop: myaddress@myhost.mydomain.org
| $HOME/bin/my.script 

which has some nice features, like the ability to detect and stop mail loops.

share|improve this answer

In postfix you could hold all incoming messages (that matches some pattern, or simply all of them), have your application pick them up in the hold/ directory and then place them back to the incoming/ directory once done. This is how the antispam filter MailScanner works when used with postfix.


In the Postfix configuration file /etc/postfix/main.cf add this line:
header_checks = regexp:/etc/postfix/header_checks
In the file /etc/postfix/header_checks add this line:
/^Received:/ HOLD

The effect of this is to tell Postfix to move all messages to the HOLD queue, when your application is done I believe you should put the mails in the incoming/ directory.

share|improve this answer

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.