I need to setup a regex catch-all function on postfix such that:
- tom.(anything)@domain.com goes to [email protected]
- phil.(anything)@domain.com goes to [email protected]
How can this be achieved in postfix?
I need to setup a regex catch-all function on postfix such that:
How can this be achieved in postfix?
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.
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
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$