0

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.

Matt
  • 1,142

2 Answers2

1

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 master.cf:

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:

#!/bin/bash
#do your stuff
#and/or:
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.

totaam
  • 201
0

I have something like that running for many years. I added a redirection in the /etc/aliases file.

The mails that need processing by munpack are sent to robot@example.com.

So I wrote in the aliases file this line robot : |"/home/robot/munpack-private.sh" user

so the mail gets processed by the munpack script and sent to the user mailbox