1

I currently have postfix piping into a PHP script to process the email via an alias.

catchall: |/var/www/vhosts/website/httpdocs/scripts/incoming_mail.php

However, I wish to use the DB config etc supplied in my CI project, so I need to provide a route such as:

catchall: |/var/www/vhosts/website/httpdocs/cli.php /incoming_mail

The desired outcome of this would be that I run the incoming_mail controller.

If I try the above the email is bounced with the following:

Action: failed
Status: 5.2.0
Diagnostic-Code: X-Postfix; cannot append message to file /incoming_mail:
cannot create file exclusively: Permission denied

Any help is greatly appreciated!

2 Answers2

3

Hi here is how I made a parser:

/etc/postfix/master.cf (postfix)

bounce-pipe    unix  -       n       n       -       -       pipe
    flags=BDFORXhqu user=deploy argv=/usr/bin/php5 /var/www/emailmanager/public/index.php

transport (postfix)

mailtoparse@example.com bounce-pipe:

index.php - get data that you would be handle

$data = file_get_contents('php://stdin');
masegaloeh
  • 18,498
Jomaar
  • 73
2

Cannot append message to file /incoming_mail: cannot create file exclusively: Permission denied

Above error message is thrown by postfix because you tell it to append email content to /incoming_mail , instead passing argument /incoming_mail to cli.php.

According to man 5 aliases

|command

Mail is piped into command. Commands that contain special char- acters, such as whitespace, should be enclosed between double quotes. See local(8) for details of delivery to command.

Since you aren't wrap the command that contain whitespace, postfix interpreted /incoming_mail as filename

/file/name

Mail is appended to /file/name. See local(8) for details of delivery to file. Delivery is not limited to regular files. For example, to dispose of unwanted mail, deflect it to /dev/null.

Solution: wrap your command in alias file with double quotes

catchall: "|/var/www/vhosts/website/httpdocs/cli.php /incoming_mail"

PS: Jommaar solution to use transport_maps and pipe can be used too :)

masegaloeh
  • 18,498