Postfix: virtual mail addresses with regular expressions

in the early days if you needed to have lots of email adresses all forwarded to the same target address and you did not want to bother to create each and every address specifically in your virtual_address_map you would simply create a catch-all address and you where good to go. however, with all the spaming happening today, we need another solution.

let's say you have a ticketing system that creates a “reply-to” address with the case-id in the address itself to track the case even if the subject changes or any other reference is lost. these dynamically assigned addresses all start with “suport-ticket” and end on “”. now you could create a mysql table and use the mysql postmap connector to dynamically “create” these addresses. another opption is to create a single entry with a regular expression, allowing all support-ticket-<ticket-id> mails to be forwarded to a certain email address.

this can be done with the regexp table of postfix. in your look for the virtual_alias_maps line and add a new regexp map to the list (comma separated): virtual_alias_maps = <whatever you had here before>, regexp:/etc/postfix/

now create a new file in /etc/postfix/ with the following contents:


to test if your regex works as you expected, you can now use the postmap command with the -q (query) option:

postmap -q regexp:/etc/postfix/

should now return your address

if that is so, run postmap to update the database and reload postfix

postmap /etc/postfix/
postfix reload 
  • postfix_virtual_mail_addresses_with_regular_expressions.txt
  • Last modified: 20.01.2019 11:34
  • by Pascal Suter