2014-09-20 05:50:50 -05:00
|
|
|
# Pipe incoming email for certain user to external script
|
2014-09-16 23:53:49 -05:00
|
|
|
|
2016-10-13 19:58:36 -05:00
|
|
|
[TOC]
|
|
|
|
|
|
|
|
This tutorial explains how to pipe incoming email for certain user to an
|
|
|
|
external script (it must be a file on your mail server, not a remote file
|
|
|
|
accessible via ssh/http/ftp/...).
|
2014-09-16 23:53:49 -05:00
|
|
|
|
|
|
|
## Configure Postfix to use your external script as transport
|
|
|
|
|
|
|
|
To pipe incoming emails to external script, you must add your external script
|
|
|
|
as Postfix transport program. Please add below line at the bottom of Postfix
|
|
|
|
config file `/etc/postfix/master.cf`:
|
|
|
|
|
|
|
|
```
|
|
|
|
external-pipe unix - n n - - pipe
|
2015-11-18 11:20:37 -06:00
|
|
|
flags=DRhu user=vmail:vmail argv=/path/to/your/external/script.sh
|
2014-09-16 23:53:49 -05:00
|
|
|
```
|
|
|
|
|
|
|
|
__Note__:
|
|
|
|
|
|
|
|
* You can use some macros to replace with corresponding information from the
|
2014-09-17 04:15:21 -05:00
|
|
|
Postfix queue manager delivery request. Refer to Postfix manual page
|
|
|
|
[pipe(8)](http://www.postfix.org/pipe.8.html) for more details. For example:
|
2014-09-16 23:53:49 -05:00
|
|
|
|
|
|
|
```
|
|
|
|
external-pipe unix - n n - - pipe
|
|
|
|
flags=DRhu user=vmail:vmail argv=/path/to/your/external/script.sh -f ${sender} -d ${user}@${domain} -m ${extension}
|
|
|
|
```
|
|
|
|
|
|
|
|
* the second line needs to be right under the first line and must start with
|
|
|
|
one (or more) whitespace, and the first line cannot start with whitespace,
|
|
|
|
otherwise 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, otherwise
|
|
|
|
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:
|
|
|
|
|
2014-09-20 18:19:12 -05:00
|
|
|
* For iRedAdmin-Pro OpenLDAP edition, please go to user profile page, under
|
2014-10-13 05:03:19 -05:00
|
|
|
tab `Advanced`, set `Relay/Transport setting` to `external-pipe`. Screenshot:
|
|
|
|
|
2017-10-28 00:38:13 -05:00
|
|
|
![](./images/iredadmin/user_profile_relay.png)
|
2014-09-20 08:19:37 -05:00
|
|
|
|
2014-09-20 18:19:12 -05:00
|
|
|
* For iRedAdmin-Pro MySQL or PostgreSQL edition, please go to user profile
|
|
|
|
page, under tab `Relay`, set `Relay/Transport setting` to `external-pipe`.
|
2014-09-16 23:53:49 -05:00
|
|
|
|
|
|
|
* If you don't have iRedAdmin-Pro, please update LDAP/MySQL/PgSQL database to
|
|
|
|
use this new transport.
|
|
|
|
|
|
|
|
* For OpenLDAP backend, please login to phpLDAPadmin, 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 'user@domain.ltd' by the real email address):
|
|
|
|
|
2014-09-20 05:55:33 -05:00
|
|
|
```
|
2014-09-16 23:53:49 -05:00
|
|
|
sql> USE vmail;
|
|
|
|
sql> UPDATE mailbox SET transport='external-pipe' WHERE username='user@domain.ltd';
|
2014-09-20 05:55:33 -05:00
|
|
|
```
|
2014-09-16 23:53:49 -05:00
|
|
|
|
|
|
|
That's all.
|