On Mon, May 23, 2022 at 09:41:39AM +0200, Ansgar Wiechers wrote: > > We got a request to match the envelope sender with a certain mail > > header (i.e. X-Something) on our relay servers for every outbound > > mails and reject the email if the sender and the value of this header > > don't match. > > > > Is this possible with postfix? > > This should be doable with restriction classes [1], but it's probably > easier (and more straightforward) to implement it with a policy service > like postfwd [2].
Actually, this is not possible with either restriction classes or policy services, since both are generally evaluated before the message content is received, and in any case do not have access to the message content. Only a milter or content_filter can apply envelope-specific header checks. Rejects in content_filters will result in a bounce, since the message is already in the queue. One can use a proxy filter to reject the message before it enters the queue, assuming that an SMTP server is preferable to a milter. -- Viktor.