9

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

How can this be achieved in postfix?

3 Answers 3

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.

4
  • 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 4, 2011 at 5:04
  • You may need to configure virtual aliases, etc if domain.com is a virtual alias.
    – Flimzy
    Nov 4, 2011 at 5:35
  • 3
    thanks! called it virtual_alias_maps = regexp:/etc/postfix/aliases and got it running.
    – thevikas
    Nov 4, 2011 at 6:59
  • Is it possible to use those kind of regexp in an LDAP setup?
    – Dolanor
    Feb 22, 2018 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

1
  • What is part_b?
    – Tigerware
    Jun 30, 2021 at 22:57
-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$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .