How To Use Regular Expressions (regex) To Forward Email In Postfix

Published Date Author: , Posted April 7th, 2015 at 8:13:30pm

Create the file /etc/postfix/virtual-regexp. For example, forward all emails with a leading eric and ending with @thewyz.net to a Gmail account:

Edit the file /etc/postfix/main.cf. Add regexp:/etc/postfix/virtual-regexp to the virtual_alias_maps line. For example:

Generate the map .db file:

This example requires the files virtual and virtual.db to exist, even if they are empty. If they are not present, simply create them:

Comments reader  2 Reader Comments

anon - Gravatar

kotchan.fun anon said on November 23, 2020, 1:02 am:

Does this work, however, while having both virtual and virtual-regexp files working in tandem? or is it a one or the other type deal

anon - Gravatar

kotchan.fun anon said on November 23, 2020, 1:43 am:

Update to that last comment, YES you can, however this guide is either outdated or wrong! for the regex addresses you wouldn’t use

/eric.*/@thewyz.net wyzaerd@gmail.com

you would instead use

/eric.*/ wyzaerd@gmail.com

you can’t include the domain in regex addresses

Leave Your Comment  Leave a comment

All fields marked with "*" are required.