September 27, 2012

Postfix: Rewrite the sender address of all mail

Filed under: Internet, UNIX/Linux/BSD — Tags: — martin @ 12:17 pm

OMG, I used to do mail for kings and queens. With properly crafted mail setups, meticulously built from the finest bits and bytes you can imagine.

But things have gone somewhat downhill from there. Now that I play the most general UNIX dude, I get this request far too often (talk about once every few weeks), and I’m not sure whether I have a proper solution for it or not. It goes like this:

“I have applications on the system, and I don’t know how, but they send mail, and I want all mail to be rewritten to a single from address. And please don’t try to tell me what you think good design looks like, but just get the damn job done.

So, the first approach was to add a pcre map in sender_canonical_maps with something like this, that matches every sender, as requested:

/.*/ godknowswhat@example.com

Directly from there, we tried to optimize away the sender_canonical file and its regex and came to this in main.cf:

sender_canonical_maps = static:godknowswhat@example.com

This actually leads to the same behaviour as it replaces any given sender with godknowswhat@example.com. Which, after a while, brought us to our first mail loop when Postfix had delivery problems and rewrote the empty bounce sender address (<>).

So now we are back to our pcre map for good, interestingly with just a single byte changed:

/.+/ godknowswhat@example.com

This rewrites all sender addresses to godknowswhat@example.com, but if a bounce appears, the sender address is not rewritten and the bounce can be delivered or at least double-bounce if it runs into additional failure.


  1. […] an example: https://binblog.info/2012/09/27/postf…outgoing-mail/ and it appears Reuti is a Postfix wizard: http://www.linuxquestions.org/questi…ostfix-852693/ […]

    Pingback by question concerning postfix, a perl script, and Amazon Simple Email Service — November 12, 2012 @ 3:18 am

  2. Ich versuche jetzt seit einem halben Tag genau das gleiche – und falle jedesmal auf die Nase. Postifx weigert sich konstant und beharrlich, meine sender-Adressen umzuschreiben (die _envelope_-Adressen, ich benutze einen Exchange-SMTP-Relay, und darf nur unter einer Adresse senden).
    Hättest du evtl. noch ein paar Tips woran das liegen könnte?

    Comment by Axel — March 22, 2013 @ 7:49 am

    • …und noch followup notification 🙂 . just in case.

      Comment by Axel — March 22, 2013 @ 7:49 am

  3. damn, found it. ganz unten in der config-datei eine doppelte sender_canonical_maps angabe mit hash: statt pcre: … bin nicht aufmerksam die tage.

    Comment by Axel — March 22, 2013 @ 9:05 am

    • Sorry, ich wollte diese Basics direkt abfragen, nachdem ich den Kommentar heute früh freigeschaltet habe, aber bis dahin hat leider die Aufmerksamkeitsspanne nicht gereicht. Gut, dass es jetzt klappt! 🙂

      Comment by martin — March 22, 2013 @ 11:29 am

      • danke trotzdem 🙂 !

        Comment by Axel — March 26, 2013 @ 9:09 am

RSS feed for comments on this post. TrackBack URI

Leave a Reply to question concerning postfix, a perl script, and Amazon Simple Email Service Cancel reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a free website or blog at WordPress.com.

%d bloggers like this: