6

I've got a Postfix setup that allows relays only from certain domains. I accomplish this using the relay_domains flag in main.cf and it queries mysql to find the list of allowed domains.

relay_domains = mysql:/etc/postfix/mysql_domains.cf

I would like to add a header_checks instruction to insert a custom header based on the result of the mysql check for relay_domains which would show which domain was relayed through Postfix. The reason for this is that if the allowed domain is .domain.com and the recipient email address is someone@subdomain.domain.com, I'd like to know which .domain.com Postfix resolved to in the lookup.

I've got the header_checks working:

/^From:/i PREPEND X-Relay-Domain: xxx

But I'm not sure how to capture the result of the domain query and use that for the header_checks PREPEND. I could also perform another mysql lookup on header_checks but I'd like to avoid that if possible.

JP Toto
  • 163
  • 1
  • 6
  • Consider this case: an email intended to two or more different domains. For this case, *there is possibility* that postfix will **append two or more header lines**. Is there a problem with that? – masegaloeh May 23 '15 at 05:39
  • @masegaloeh in that case it would be ok because of the way I process mail afterward but that's a very good point you raise. – JP Toto May 24 '15 at 14:36

1 Answers1

6

Perhaps, you can use check_recipient_access from postfix.

smtpd_recipient_restriction = ... 
                      ... 
                      check_recipient_access pcre:/etc/postfix/addheader
                      ...

File /etc/postfix/addheader has content like this

/.+@(.+)/  PREPEND X-Relay-Domain: $1

In access table, PREPEND action will add header in your email. In this case, this map will add domain parts of your recipient.

masegaloeh
  • 17,978
  • 9
  • 56
  • 104