Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

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.

share|improve this answer
    
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 tom.curry@domain.com is not a real mailbox, but thats the point of alias. it should relay mail to tom@other.com which is elsewhere without complaining. (I use postfix with working mailman lists on ubuntu if that helps) –  thevikas Nov 4 '11 at 5:04
    
You may need to configure virtual aliases, etc if domain.com is a virtual alias. –  Flimzy Nov 4 '11 at 5:35
1  
thanks! called it virtual_alias_maps = regexp:/etc/postfix/aliases and got it running. –  thevikas Nov 4 '11 at 6:59

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$
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.