Pipe all Postfix email for a domain to PHP script - Centos7/EC2
Solution 1:
Amazingly, Wombles comment helped and I was very close with my initial question.
This worked for me. This is to redirect/pipe all email for one domain (not in hostname) to a php script on a CentOS server using Postfix (assuming you have deal with DNS and selinux/firewalls):
-
Virtual Alias
Redirect the email to a local user by updating
/etc/postfix/virtual
:@support.mydomain.com apache@localhost
Rebuild the virtual alias db with
postmap /etc/postfix/virtual
. -
Tell Postfix To Use Our Virtual Alias db in
/etc/postfix/main.cf
:virtual_alias_maps = hash:/etc/postfix/virtual
-
Virtual Domain
Update
/etc/postfix/main.cf
with a virtual domain, so it knows to accept email for your the domain, otherwise you'll get a "454 4.7.1 Relay access denied" error:virtual_alias_domains = support.mydomain.com
-
Accept Connections
Tell postfix to allow connections from the internet (not jsut local) by upadting
/etc/postfix/main.cf
:inet_interfaces=all
-
Update Alias
Update
/etc/aliases
to redirect email addressed to the localuser to a script:#apache:root
(unconnect any existing entry for your local user)apache: "|sudo /usr/bin/php -q /var/www/mydomain.com/my-script.php"
-
Rebuild Aliases & Restart Postfix
sudo newaliases
sudo postfix reload
sudo service postfix restart
I hope this helps others, there didn't seem to be a compiled/concise post on this.