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!

Jim Wright
  • 113
  • 4

2 Answers2

2

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
  • 17,978
  • 9
  • 56
  • 104
Jomaar
  • 43
  • 6
  • Hi Jomaar, this is similar to what I have at the moment, but I need to pass an argument into the script – Jim Wright May 07 '15 at 13:03
  • Hi Jim, than add the param after the `argv=/usr/bin/php5 /var/www/emailmanager/public/index.php` like `argv=/usr/bin/php5 /var/www/emailmanager/public/index.php job parser` – Jomaar May 07 '15 at 13:12
  • Sorry, I'm not too great with postfix. I am currently pointing lots of domains to the catchall alias in the /etc/postfix/virtual file. Would I have to make changes there too or would this act as an alias also? – Jim Wright May 07 '15 at 14:01
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
  • 17,978
  • 9
  • 56
  • 104
  • I ended up piping to a small script, which piped stdin to cli.php with the argument. But when I have got some time I will try this out! – Jim Wright May 08 '15 at 11:49