• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Postfix Mail Aliases to forward to Command Pipe

S

szlampy

Guest
I am running Plesk 9.3.0 witht the postfix mail client on CentOS Linux.

I am trying to get a mail account to forward/redirect mail to script.

I don't really want to break the plesk control panels for managing the server.

The panels won't simply allow you to enter the pipe command (e.g. "|/usr/bin/perl /path/to/script") as an alias into the control panels as they have some email verification/normalization scripts running on the form input.

I am not 100% sure but from my investigations it appears that Parallels have configured Postfix to handle aliases from the MySQL DB called PSA via the mail, mail_aliases, mail_redir tables.

So I have set-up an aliases via the panels to forward the mail address I want handled by a script ([email protected]) to forward to another address ([email protected]) and that all works as expected.

Then I logged into the DB and manually modified the entry in the DB so that the address being forwarded too ([email protected]) is changed to the pipe command to run the script ("|/usr/bin/perl /path/to/script").

Unfortunately mail being sent to [email protected] is still being forwarded to [email protected] and NOT "|/usr/bin/perl /path/to/script" as expected.

I can therefore presume that this is happening because there's a script that updates the Postfix aliases from the DB once the data has been inputed, and manually editing the DB isn't triggering this script. That is why the old configuration is still being used.

The remedies as I see it now, are as follows:

a) Trigger the script that updates the Postfix aliases. (I've tried the obvious "postfix reload")
b) Disable/Change the verification on the plesk panels so that the script will now accept email addresses and scripts as valid entries for forwarding mail too.

SO... I'm after either the location/name of the script that updates the postfix aliases from plesk, or the location/name of the script that checks the input from the plesk panels. I partially suspect it may even be the same script.

Can anyone help me here?
 
Different Approach

We struggled for a while to a find a solution that work for this and was compatible with Plesk 9.2+ and failed.

Finally we opted for a completely different approach.

In the end we adopted a method using a perl script that is run as a cron job every minute. It simply checks the mailbox for new messages and processes them as we would have had the other script doing - it's not as 'instant' but it's a working solution.
 
plesk postfix pipe

Well, i've managed to make it work (i needed to make socketmail pipe work .. had qmail before)

Set up in plesk Mail accounts -> Mail settings -> Mail to nonexistent user -> Forward to address [email protected] (create [email protected] with mailbox).

In /etc/postfix/transport:

[email protected] yourpipename:
----
(postmap /etc/postfix/transport)

In main.cf:
transport_maps = hash:/var/spool/postfix/plesk/transport, hash:/etc/postfix/transport
----

In master.cf:
yourpipename unix - n n - - pipe flags=O user=apache:apache argv=/usr/bin/php -c /etc/php-cli.ini -q /var/www/vhosts/domain.com/httpdocs/system-files/mx.php ${recipient}
----

(beware that ${recipient} will be [email protected], so i suggest you gather the To: field from X-Original-To: field which will be added by postfix-pipe due to the "O" flag.
In the documentation says you can use ${original_recipient} instead of ${recipient} but it works if you have postfix 2.5 or greater )

Now everytime a mail comes to [email protected] it pipes to "yourpipename" in master.cf and does not store locally.

And it works like a charm!

Part of credits go to: http://www.hostnexus.com/forum/ples...ting-email-pipe-plesk-9-2-2-a.html#post110122

Cheers.
 
In main.cf:
transport_maps = hash:/var/spool/postfix/plesk/transport, hash:/etc/postfix/transport
----

In master.cf:
yourpipename unix - n n - - pipe flags=O user=apache:apache argv=/usr/bin/php -c /etc/php-cli.ini -q /var/www/vhosts/domain.com/httpdocs/system-files/mx.php ${recipient} actually does the deal :) it works.
 
Last edited by a moderator:
I am trying to get this work but I have this error in mailog:

Jun 21 13:55:28 lin5 postfix/pipe[27812]: C4DDF260846: to=<[email protected]>, relay=pipeDomain, delay=0.24, delays=0.15/0.01/0/0.08, dsn=5.3.0, status=bounced (Command died with status 1: "/usr/bin/php". Command output: Could not open input file: /var/www/vhosts/domain.com/httpsdocs/front/piping/index.php )

Permissions
/var(755)/www(755)/vhosts(755)/domain.com(755)/httpsdocs(755)/front(755)/piping(755)/index.php(755)

/etc/postfix/master.cf
pipeDomain unix - n n - - pipe flags=O user=apache:apache argv=/usr/bin/php -c /etc/php-cli.ini -q /var/www/vhosts/domain.com/httpsdocs/front/piping/index.php ${recipient}

/etc/postfix/main.cf
transport_maps = hash:/var/spool/postfix/plesk/transport, hash:/etc/postfix/pipeDomain

/etc/postfix/pipeDomain
[email protected] pipeDomain: description log Sent to pipeDomain

/etc/postfix/pipeDomain.db

In Mail settings -> Mail to nonexistent user -> Forward to address [email protected] (created [email protected] with mailbox).


I plave plesk 10.4.4

please help!!
 
I piped mail through Plesk using Postifix by:
Code:
vi /var/qmail/mailnames/domain.com/email_alias/.qmail
and in it you can add something like:
Code:
| /usr/bin/php /var/www/vhosts/domain.com/httpdocs/your_script_path/pipe.php
 
I think is a permission problem. If I put the php script in /etc/postfix/index.php

The pipe works

Jul 3 17:13:41 lin5 postfix/pipe[9769]: A91F4260814: to=<[email protected]>, relay=pipe_s4_emsrv_es, delay=0.27, delays=0.17/0/0/0.1, dsn=2.0.0, status=sent (delivered via pipeDomain service)

but in /var/www/vhosts/domain.com/httpsdocs/front/piping/index.php dont:

Jul 3 17:45:42 lin5 postfix/pipe[10332]: 5591C2606F4: to=<[email protected]>, relay=pipeDomain, delay=0.31, delays=0.18/0.01/0/0.12, dsn=5.3.0, status=bounced (Command died with status 1: "/usr/bin/php". Command output: Could not open input file: /var/www/vhosts/domain.com/httpsdocs/front/piping/index.php )
 
Back
Top