10

I need to setup a regex catch-all function on postfix such that:

  • tom.(anything)@domain.com goes to tom@other.com
  • phil.(anything)@domain.com goes to phil@other.com

How can this be achieved in postfix?

Gareth
  • 19,080
thevikas
  • 381

3 Answers3

19

Add this to your main.cf:

alias_maps = regexp:/etc/postfix/aliases

Then create /etc/postfix/aliases as follows:

/^tom\..*@domain.com$/     tom@other.com
/^phil\..*@domain.com$/    phil@other.com

See the regexp table documentation for additional information.

Flimzy
  • 4,465
4

I'll add this for people who are wondering if it is possible to handle multiple address aliases with less configuration:

/^(.*)\..*@domain.com$/     $1@other.com

This will forward:

<anything>.<part_b>@domain.com

to

<anything>@other.com

L422Y
  • 162
-1

I don't know Postfix, but the regex you're looking for is:

/^.*(\..*)@(domain).com$/

Then you substitute the first matching group with nothing (empty string), and the second group with "other".

As an example, in Perl you would do:

my $regex = '^.*(\..*)@(domain).com$';

$your_string =~ /$regex/;
$aux = $2;
$your_string =~ s/$1//;
$your_string =~ s/$aux/other/;

print $your_string;

Of course this works only if email address has "domain" as domain. If you want domain to be anything, then the regex would be:

^.*(\..*)@(.*).com$
Gareth
  • 19,080
m0skit0
  • 1,337