This article main reference: Http://serverfault.com/questions/258469/how-to-configure-postfix-to-pipe-all-incoming-email-to-a-script
???? During the Postfix mail server Setup, it is sometimes hoped that postfix will be able to move to execute a specific script after receiving the message. Similar to the actual function has, mail automatic reply program, mail content filtering and so on. This function can be implemented by configuring the Postfix. This article describes a way to move to execute a specific shell script after Postfix receives the message.
???? The method used in this article is to solve the idea is: by modifying the transmission table (transport_maps), so that Postfix received the message, not directly forwarded to the MDA, and transferred to a specific script program.
???? Specifically, five steps are required:
1. Create a transmission table to indicate what requirements will be forwarded to the message
2. Compiling the transfer table into a familiar data format for Postfix
3. Set up a service in the Postfix master.cf file to tell Postfix that the message needs to be forwarded to a specific script
4. Set the Transport_maps parameter in the main.cf of Postfix and tell Postfix to use the transfer table
???? Here are the specific actions for each step
1, create the file /etc/postfix/transport
, tell postfix the following domain name received mail will start the service named Mytransportname
mydomain.com mytransportname:
2. Compile the file into a Postfix recognized format
$ sudo postmap /etc/postfix/transport
3, in the/ETC/POSTFIX/MASTER.CF to increase the transmission service:
mytransportname unix - n n - - pipe
flags=FR user=localuser argv=/path/to/my/script.py
${nexthop} ${user}
Where the flags are the service identity; user is the username (attention to the permissions issue); argv is the address of the script program. Here, the script that this service needs to execute is /path/to/my/script.py
4. Finally, in the, add the /etc/postfix/main.cf
configuration of the transmission table in
transport_maps = hash:/etc/postfix/transport
???? After you complete the steps above, restart Postfix (service postfix restart). Note that the script must have executable permissions and that the user user has permission to execute the script.
Postfix to execute a specific script after receiving mail