0

I have a situation where emails sent to marketing@domain1.com are configured to go to a listserver via virtual_alias_maps:

virtual_alias_maps = $virtual_maps hash:/Library/Server/Mail/Data/listserver/aliases/list_server_virtual

I also have emails to marketing@domain2.com go there as well, but the listserver sucks (I'm stuck with it), and refuses to accept anything that isn't addressed to domain1.com. So, I thought rewriting might be the solution. Unfortunately, I'm not sure that rewriting ACTUALLY rewrites the To: header, which is what I was expecting and what I need to occur (I'm assuming my expectations are flawed).

So, I added:

 recipient_canonical_maps = hash:/Library/Server/Mail/Config/postfix/canonical

And /Library/Server/Mail/Config/postfix/canonical contains:

 marketing@domain2.com               marketing@domain1.com

Now, emails sent to marketing@domain2.com are getting redirected ("rewritten"?) to marketing@domain1.com, but when the email comes through, it still says "To: marketing@domain2.com".

So, to make things easier to troubleshoot, I updated canonical to rewrite marketing@domain2.com to come straight to me (bypassing any potential listserver confusion):

 marketing@domain2.com               me@domain1.com

But again, when emails are sent to: marketing@domain2.com, they are correctly delivered to me@domain1.com, but the headers still show "To: marketing@domain2.com"

Is there any way to get Postfix to literally rewrite the 'To:' header?

1

Modifying headers is not recommended and Postfix has abandoned it for reasons explained in Postfix Address Rewriting:

Postfix versions 2.1 and earlier always rewrite message header addresses, and append Postfix's own domain information to addresses that Postfix considers incomplete. While rewriting message header addresses is OK for mail with a local origin, it is undesirable for remote mail:

  • Message header address rewriting is frowned upon by mail standards,
  • Appending Postfix's own domain produces incorrect results with some incomplete addresses,
  • Appending Postfix's own domain sometimes creates the appearance that spam is sent by local users.

Postfix versions 2.2 give you the option to either not rewrite message headers from remote SMTP clients at all, or to label incomplete addresses in such message headers as invalid.

It's possible to change this behavior for canonical address mapping:

NOTE: Postfix versions 2.2 and later rewrite message headers from remote SMTP clients only if the client matches the local_header_rewrite_clients parameter, or if the remote_header_rewrite_domain configuration parameter specifies a non-empty value. To get the behavior before Postfix 2.2, specify

local_header_rewrite_clients = static:all

Also notice that if the headers are DKIM signed, DKIM will fail if tested after rewriting the headers. That's one practical reason why this might not be a good idea.

  • I had tried this before posting. I'm running postfix 3.1.1. I have local_header_rewrite_clients = static:all in main.cf and I have the mapping as listed above under recipient_canonical_maps. It's correctly DELIVERED to the recipient mapped in recipient_canonical_maps but the recipient is not modified. The rewritten recipient is nowhere to be found in the headers. – jaydisc Apr 27 '18 at 8:22
  • I found why this didn't work. In master.cf, smtpd had -o receive_override_options=no_address_mappings applied. I'll have to figure out why that was on and confirm I can turn it off. – jaydisc Apr 27 '18 at 8:32
  • Good you found a solution. BTW current subversion for this 3.1 legacy release is 3.1.8. Not a huge problem, since Postfix security vulnerabilities are rare. – Esa Jokinen Apr 27 '18 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.