Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have a Postfix server that receives mail from our application servers. Senders are in the form user@host.fqdn (where host.fqdn can vary, depending on source server) and recipients can be internal or external users.

Messages going to external users should have the sender changed to I have tried using canonical maps, but since that is handled by the cleanup daemon, before any transport decisions are made, it would affect all sender addresses.

I have also tried creating a custom smtp transport with generic mappings and configuring transport_maps to use that custom smtp transport for external domains. However, generic mappings affect both sender and recipient addresses.

Lastly, I've tried the following:

  • Create a custom smtpd daemon that specifies sender canonical maps and a unique transport table.
  • Send all externally addressed mail to that custom daemon. Ideally, sender canonical maps would transform the sender address and the unique transport table would relay messages to the internet.

However, evidently, only one transport table can be used per Postfix instance.

I want to avoid creating an entirely new Postfix instance to accommodate this rewriting. Any suggestions? (and thanks in advance)

share|improve this question

Disclaimer: this answer won't work as intended when process email which had multiple recipients with both internal and external domain in it

With postfix multi instance, the solution would be trivial. Just setup transport_maps to second instance, then do rewriting in second instance.

Without multiple instance, you need two smptd processes, two cleanup processes and access map.The idea is do filtering in access maps instead in transport_maps. When an email has external domain recipient, it transported to second smtpd daemon. Then second smtpd daemon would call second cleanup daemon. First cleanup daemon won't have canonical maps parameter, while in second cleanup daemon, we will add that parameter to do rewriting.

In, define check_recipient_access in smtpd_*_restriction. For example:

smtpd_recipient_restriction =
   check_recipient_access hash:/etc/postfix/external-filter

In external-filter file define a filtering mechanism    FILTER smtp:[]:12525

In this example we will setup second smtpd daemon listen in port 12525.

Now, setup second smtpd and cleanup daemon in

[]:12525  ....  smtpd -o cleanup_service_name=cleanup_rewrite

cleanup_rewrite .... cleanup -o canonical_maps=hash:/etc/postfix/mysender_rewriting

File mysender_rewriting would contains a sender mapping as you intended.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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