First, go to master.cf and register your script "myhook" by adding the following line: myhook unix - n n - - pipe flags=F user=www-data argv=/path/to/script.sh ${sender} ${size} ${recipient} Also, edit smtp line to tell Postfix to run the filter for any mail arriving via the SMTP delivery: smtp inet n - - - - smtpd -o content_filter=myhook:dummy Please note that if you are sending mails using the "sendmail" command, the filter will not trigger. In this case, add the option after the "pickup" delivery method: pickup fifo n - - 60 1 pickup -o content_filter=myhook:dummy Restart postfix: postfix reload Make your script readable and executable by anybody: chmod +rx script.sh Note that script is always triggered for any mail arriving. To specify exact address see @MariusMatutiae answer.