-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
  • 17,978
  • 9
  • 56
  • 104
  • Got this working but haven't a clue how I did so. I will need to rebuild the server again in a couple of weeks time. Once I do I will post the steps here. – user1913559 Aug 11 '14 at 02:25

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,694
  • 1
  • 25
  • 31
  • Postfix _already does this_, which is the behavior he's complaining about. – Michael Hampton Aug 08 '14 at 13:20
  • Where exactly is he complaining about getting an `X-Original-To:`-header? – etagenklo Aug 08 '14 at 13:28
  • Unfortunately this cannot work because I want this file to later be indexed by a third party app. Letting Postfix rewrite the address will mean that the third party app will ultimately read the value in the "To" field as root@domain.com and index the document incorrectly. – user1913559 Aug 08 '14 at 21:03