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: