IRedMail/FAQ/Pipe.Incoming.Email.For.Certain.User.To.External.Script

From iRedMail

Revision as of 15:44, 14 October 2011 by ZhangHuangbin (Talk | contribs)
Jump to: navigation, search

Contents


Summary

This tutorial explains how to pipe incoming email for certain user to external script.

Configure Postfix

We need to edit the Postfix config file /etc/postfix/main.cf to handle an additional transport map.

Edit /etc/postfix/main.cf, prepend 'hash:/etc/postfix/transport,' in Postfix setting "transport_maps".

File: main.cf
transport_maps = hash:/etc/postfix/transport, [...OMIT EXISTING SETTINGS HERE...]

Update file /etc/postfix/transport, add below line:

File: /etc/postfix/transport
# Pipe incoming mails for user "rt@example.com" to external script.
# External script is defined as Postfix transport "external-pipe" in /etc/postfix/master.cf.
rt@example.com     external-pipe

Execute command to create (or update) transport db:

Terminal:
# postmap hash:/etc/postfix/transport

Update file /etc/postfix/master.cf to define new Postfix transport for external script. Add below line at the bottom of file /etc/postfix/master.cf:

File: /etc/postfix/master.cf
external-pipe         unix    -       n               n               -               -       pipe
    flags= user=vmail:vmail argv=/path/to/your/external/script.sh

Note: 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

Note 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.

Of course you can add parameters after script. for example, dovecot delivers mails locally with its MDA program:

File: master.cf
dovecot unix    -       n       n       -       -      pipe
    flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${user}@${domain}

Now restart Postfix service to make it work.

Terminal:
# /etc/init.d/postfix restart
Personal tools