I want to create a global alias for all my domains to catch all mail to addresses like postmaster@
I've added theses lines to aliases.pcre
:
/(MAILER-DAEMON|postmaster|abuse|webmaster)@(.*)$/ me@mydomain
and in main.cf
virtual_alias_maps = pcre:/etc/postfix/aliases.pcre
but it catches mails to external domains too, i.e. redirecting to me mails sent to postmaster@external.com
Can I redirect all mail sent to theses addresses but only if domain is in virtual_mailbox_domains
? (without writing the domain names in aliases.pcre
* update *
users, domains, alias.. are stored in a database, using postfixadmin to manage it.
alias tables looks like this:
mysql> describe alias;
+----------+--------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------------------+-------+
| address | varchar(255) | NO | PRI | NULL | |
| goto | text | NO | | NULL | |
| domain | varchar(255) | NO | MUL | NULL | |
| created | datetime | NO | | 0000-00-00 00:00:00 | |
| modified | datetime | NO | | 0000-00-00 00:00:00 | |
| active | tinyint(1) | NO | | 1 | |
+----------+--------------+------+-----+---------------------+-------+
ideally it should respect alias from database if it's set, and only redirect mail for addresses without alias
Best Answer
As alternative, instead long query as proposed above you can split to two sql maps
Both files has same parameter except the query. For
/etc/postfix/mysql-virtual-aliases.cf
, you can use default query from postfixadminAnd for
my-custom-query.cf
you have queryHow it works
If your first maps
mysql-virtual-aliases.cf
returns null, then postfix will attempt to query to second mapsmy-custom-query.cf
.Pros:
mysql-virtual-aliases.cf
, then you just run one simple query.Cons:
mysql-virtual-aliases.cf
, you must run additional second query.