-1

I'm trying to get Postfix to pipe ALL email coming in on a specific domain to a PHP script. So far I've been able to do this via a tutorial I found on the web and also editing the /etc/postfix/virtual file with something like what's below;

@domain.com root

The problem is that Postfix is re-writing the original recipient email address (for example my_fake_email@domain.com) to root@domain.com and the PHP script receiving the email does not get the original recipient (my_fake_email@domain.com). It is important that the PHP script sees my_fake_email@domain.com instead of root@domain.com.

Is it possible for Postfix to direct all incoming mail to the PHP script without modifying the address like in the example above?

Note: There can/will potentially be 10,000's of incoming email addresses.

Any ideas on how I can get Postfix to do what I want?

masegaloeh
  • 18,498

1 Answers1

1

You could set an additional header via Postfix:

create a /etc/postfix/appendheader.regexp:

/(.+)/ PREPEND X-Original-To: $1

in /etc/postfix/main.cf:

smtpd_data_restrictions = pcre:/etc/postfix/append_header.regexp

This will add an X-Original-To:-header with the original mail address before it's getting rewritten. Have your PHP-Script parse this header instead of the To:-Header.

etagenklo
  • 5,994
  • 1
  • 29
  • 33