It's actually quite simple: I want to pass all incoming emails to a PHP-script, but only as a copy, the original email shall still be delivered to the mailbox as usual.
I just can't seem to get it working. I've tried the following
(1) Created a catchall-alias (mysql):
@mydomain.tld pipe@mydomain.tld
(2) Created a regex-transport mapping in /etc/postfix/mailpipe.cf (basically means: apply to all emails of mydomain.tld)
/.*@mydomain\.tld/ mailpipe:
(3) integrated it all in /etc/postfix/main.cf:
transport_maps = ... regexp:/etc/postfix/mailpipe.cf
virtual_alias_maps = proxy:mysql:/etc/postfix/....
(4) Added the transport to /etc/postfix/master.cf:
mailpipe unix - n n - - pipe
flags=FR user=localuser argv=/path/to/my/script.php
${nexthop} ${user}
The script:
#!/usr/bin/php -q
<?php
$file = '/home/localuser/pipe/log.log';
$input = file_get_contents('php://input');
file_put_contents($file, $input, FILE_APPEND | LOCK_EX);
So the setup seems to work, the script is hit on incoming emails, but the $input
is empty (works with any other string though). The email is being processed and then removed/discarded. So here are my 2 questions:
How can I access the contents of the email from the script?
How can I prevent the email from being discarded after processing? Is there a way to pass one copy to the inbox as usual and another one to the script for processing?