0

I have a postfix mail server set up and mapped to different unix accounts on the server. I want to be able to accept mail to specific addresses defined in /etc/postfix/valias and route to a mapped unix account unless it doesn't exist as an alias then goes to a catchall unix users mailbox.

I have been attempting to use regex as a way to accomplish this but it still doesn't work. Everything is being routed to the catchall account regardless of the rules in place.

/etc/postfix/valias 

test@example.com                                         unix_acct1
user1@example.com                                        unix_acct2
/user2@example.com$/                                     unix_acct1
/^.*@example.com$/                                        catchall_unix_acct

Results of postmap tests that appear to pass correctly

 postmap -q "user2@example.com" regexp:/etc/postfix/valias

 postmap: warning: regexp map /etc/postfix/valias, line 1: ignoring unrecognized request
 postmap: warning: regexp map /etc/postfix/valias, line 2: ignoring unrecognized request
 unix_acct

on a non existent email alias on the domain

 postmap -q "no-exist@example.com" regexp:/etc/postfix/valias

 postmap: warning: regexp map /etc/postfix/valias, line 1: ignoring unrecognized request
 postmap: warning: regexp map /etc/postfix/valias, line 2: ignoring unrecognized request
 catchall_unix_acct

When I send emails to any address defined as valias or not they all end up in catchall_unix_acct unless I take it out. As mentioned I only want the catchall alias to receive mail if the address its sent to isn't set up as an alias. Is there something I am missing to accomplish this?

Thanks!

3
  • Maybe the first two lines (those without the /) prevent the correct parsing of the third line. Does it work if you delete them? You should replace /^.*@example.com$/ with /@example.com$/. This pattern has lower precedence than /user2@example.com$/. May 22 '20 at 0:00
  • Thanks @HaukeLaging I made the suggested changes and unfortunately it still has the same behavior, everything goes to the catchall mailbox. I no longer get the first 2 warnings as before though in the postmap checks.
    – jmp91
    May 22 '20 at 0:14
  • Is there a typo anywhere? The postmap -q output seems to be unix_acct but is supposed to be unix_acct1. May 22 '20 at 0:17
0

You have 2 steps to do

modify /etc/postfix/main.cf and append this line

virtual_alias_maps = regexp:/etc/postfix/valias

my file /etc/postfix/valias

/^test@example.com$/                                         debian
/^user1(\+.*)?@example.com$/                                ubuntu$1
/^user2(\+.*)?@example.com$/                                debian$1
/^.*@example.com$/                                          root

address on line 2 & line 3 allow the plus extension .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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