From iRedMail
Revision as of 18:05, 19 April 2012 by ZhangHuangbin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search



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

Configure Postfix to use your external script as transport

Update file /etc/postfix/ to use your external script as Postfix transport. Add below line at the bottom of file /etc/postfix/

File: /etc/postfix/
external-pipe         unix    -       n               n               -               -       pipe
    flags= user=vmail:vmail argv=/path/to/your/external/


  • 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: For example:
File: /etc/postfix/
external-pipe         unix    -       n               n               -               -       pipe
    flags=DRhu user=vmail:vmail argv=/path/to/your/external/ -f ${sender} -d ${user}@${domain} -m ${extension}

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

# /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.

  • If you have iRedAdmin-Pro-LDAP installed, please go to user profile page, under tab Advanced, set Relay/Transport setting to 'external-pipe' (without quotes). Screenshot for your reference:
  • If you have iRedAdmin-Pro-MySQL or iRedAdmin-Pro-PGSQL installed, please go to user profile page, under tab Relay, set Relay/Transport setting to 'external-pipe' (without quotes).
  • If you don't have iRedAdmin-Pro installed, you have to manually update LDAP/MySQL/PgSQL database to use this new transport.
    • For OpenLDAP backend, please login to phpLDAPadmin, please add new attribute mtaTransport for your user, set its value to 'external-pipe'.
    • For MySQL/PostgreSQL backend, please execute below command with SQL command line tool (Replace '' by the real email address):
sql> USE vmail;
sql> UPDATE mailbox SET transport='external-pipe' WHERE username='';

That's all.

Personal tools