Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to run a script over email received by a virtual mailbox. I was hoping to do this with .forward in the virtual mailbox directory but it doesn't seem to be executing the script.

The idea is to extract attachments via munpack into another directory, but only when sent to that mailbox.

Mail Server is Postfix.

share|improve this question
You need to specify a lot more: what mail server, how it is setup, etc.. – totaam Jan 4 '12 at 9:03
sorry, I thought the tags would indicate that, Postfix. There is a lot of config, where should I start? – Ablue Jan 4 '12 at 11:49
since your question is about virtual mailbox, pretty much anything related to that – totaam Jan 4 '12 at 12:10
possible duplicate of Run script on incoming email message to postfix – mailq Jan 4 '12 at 21:55
@mailq I think you are right. I missed that one. – Ablue Jan 4 '12 at 22:25
up vote 1 down vote accepted

One option I have used before is to define your own delivery wrapper (I use maildrop for actual delivery - but this should work with any) then you can just do your stuff there. Something like this in

maildrop unix -     n   n   -   -   pipe
  flags=Rhu user=vmail:vmail argv=/usr/bin/maildrop-wrapper 
  -d ${user}@${nexthop} -f ${sender} -A X-Delivery:maildrop

In maildrop-wrapper, do your stuff then just call the real maildrop:

#do your stuff
exec /usr/bin/maildrop $@

You can run it before or after calling maildrop, important note: the script will receive the email via stdin, so you will have to buffer it if you intend to pass it to maildrop later (which the example above does not do). I would probably recommend using perl for this as there are more mail handling libraries there than in bare shell.

Edit: If you only want to do this for a single user then this is overkill, have a look at maildrop - in particular the section about "external commands" via backticks. Define a maildroprc for this user with the rules required.

share|improve this answer
In order to use this approach and apply the filtering to only a specific mailbox I would need to write in a condition for the recipient... It seems messy for what I want to achieve. – Ablue Jan 4 '12 at 23:46

Your Answer


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.