0

I've read a few articles, including posts on here, but there doesn't seem to be a clear concise answer.

I have CentOS7 running Postfix on an EC2 instance on AWS. I want to direct all emails for a domain (@support.mydomain.com) to a PHP script. The server hostname is not set to the domain (hostname is default ip-1-2-3-4.awsregion.internal.compute).

I have set an MX record for support.mydomain.com to point to www.mydomain.com.

From what I have read, I need a virtual alias to handle the domain.

I have tried:

  • adding @support.mydomain.com apache@localhost to /etc/postfix/virtual
  • running postmap /etc/postfix/virtual
  • adding virtual_alias_maps = :hash:/etc/postfix/virtual and inet_interfaces=all to /etc/postfix/main.cf
  • adding apache: "|php -q /var/www/mydomain/my-script.php"
  • newaliases
  • postfix reload
  • service postfix restart

/var/log/maillog shows email a ```454 4.7.1 Relay access denied" error - at least this shows DNS/firewalls are OK ...

Would appreciate where to go from here or a new guide from the start.

Egg
  • 121
  • 1
  • 5

1 Answers1

2

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):

  1. 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.

  2. Tell Postfix To Use Our Virtual Alias db in /etc/postfix/main.cf:

    virtual_alias_maps = hash:/etc/postfix/virtual

  3. 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

  4. Accept Connections

    Tell postfix to allow connections from the internet (not jsut local) by upadting /etc/postfix/main.cf:

    inet_interfaces=all

  5. 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"

  6. 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.

Egg
  • 121
  • 1
  • 5