You can use some macros to replace with corresponding information from the Postfix queue manager delivery request. Refer to Postfix manual page for more detail: http://www.postfix.org/pipe.8.html For example:

that the 2nd line needs to be right under the first and must start with whitespace, and the first line cannot start with whitespace or postfix will fail with 'unexpected command-line argument' errors. Also make sure the user= line is pointing to a valid user with permissions to execute the script. This user must not be the postfix or root user or the pipe will fail.

Now restart Postfix service to make this new transport available:

Terminal:

# /etc/init.d/postfix restart

Update per-user transport to use this new transport

We need to update per-user transport setting, so that all emails delivered to this user will be piped to this new transport - your script.