9

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

How can this be achieved in postfix?

Gaff
  • 18,569
  • 15
  • 57
  • 68
thevikas
  • 351
  • 2
  • 5
  • 16

3 Answers3

18

Add this to your main.cf:

alias_maps = regexp:/etc/postfix/aliases

Then create /etc/postfix/aliases as follows:

/^tom\..*@domain.com$/     [email protected]
/^phil\..*@domain.com$/    [email protected]

See the regexp table documentation for additional information.

Flimzy
  • 4,374
  • 21
  • 41
  • I setup as suggested. getting bounce as: (Action: failed, Status: 5.1.1, Diagnostic-Code: x-unix; user unknown). I checked postconf -m and saw regexp supported but still not working. bounce complain [email protected] is not a real mailbox, but thats the point of alias. it should relay mail to [email protected] which is elsewhere without complaining. (I use postfix with working mailman lists on ubuntu if that helps) – thevikas Nov 04 '11 at 05:04
  • You may need to configure virtual aliases, etc if domain.com is a virtual alias. – Flimzy Nov 04 '11 at 05:35
  • 3
    thanks! called it virtual_alias_maps = regexp:/etc/postfix/aliases and got it running. – thevikas Nov 04 '11 at 06:59
  • Is it possible to use those kind of regexp in an LDAP setup? – Dolanor Feb 22 '18 at 15:19
4

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

/^(.*)\..*@domain.com$/     [email protected]

This will forward:

<anything>.<part_b>@domain.com

to

<anything>@other.com

L422Y
  • 162
  • 7
-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$
Gaff
  • 18,569
  • 15
  • 57
  • 68
m0skit0
  • 1,337
  • 7
  • 16