Rewriting addresses in Postfix with regular expressions

Today my employer asked me to look into Postfix. We should take an address like root@some.obscure.host.local.lan and make it into root.some.obscure.host@domain.tld.

Looking at the (good) documentation from Postfix, I managed to get a solution. You should change in /etc/postfix/main.cf:

canonical_maps = regexp:/etc/postfix/rewrite

and the /etc/postfix/rewrite file will contain:

/^(.*)@(.*)\.local\.lan$/     ${1}.${2}@domain.tld
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

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 )

Google+ photo

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

Connecting to %s