2

I want to prepend a header with postfix to every outgoing mail from a specific domain. At the moment i use:

check_sender_access hash:/etc/postfix/prepend

with /etc/postfix/prepend:

my.domain PREPEND Header: value

this works quite nice, but when i send a e-mail to several recipients, then the header is added multiple times, one for each recipient, to each of the outgoing mails.

so when i send a mail to 4 persons, each of them receives a mail, which contains the header 4 times.

sysadmin1138
  • 133,124
  • 18
  • 176
  • 300
allo
  • 1,620
  • 2
  • 22
  • 39

2 Answers2

2

Just for the record, because I stumbled over this rather old question (because I had a quite similar problem):

There is an easy solution: put your check_sender_access directive into smtpd_data_restrictions.

Explanation: As far as I checked, smptd_relay|recipient|sender|client_restrictions are evaluated once for each recipient of the message, at least if smtpd_delay_reject is set (which is the default and sensible in most cases). Thereby, if you put it in any of these, the header will be prepended once per recipient of the message. Of course, this only works if your condition does not depend on the recipient list of the message.

andwei
  • 21
  • 2
  • This is a good idea, but does not work together with applying it to outgoing mails only. Currently I match if one of my own domains is the sender domain. This is not the best solution either, but currently I do not know a better way to do this. – allo Apr 01 '20 at 14:23
1

There is no "simple" solution for this. You need to define a second smtpd instance in master.cf, have it access it's own cleanup instance, and define a header_checks maps for this cleanup instance. Then, you'd prepend the header on some unique header present in that mail, i.e. message-id.

Stefan Förster
  • 1,151
  • 5
  • 8
  • I already thought so, but thats a lot of overkill. What do you mean by prepending on Message-ID? at the moment, postfix-map checks for a *known* value, but a Message-ID is different (and unique) each time. – allo Sep 01 '13 at 12:05
  • if /Message-Id/ prepend header – Stefan Förster Sep 01 '13 at 12:51