Mail redirection in Postfix

For developer machines, to redirect all outgoing mail to a single addres;

Create /etc/postfix/virtual-regexp with the following content:

/.+@.+/ email@gmail.com 

Edit /etc/postfix/main.cf and add regexp:/etc/postfix/virtual-regexp to the virtual_maps configuration. The end result might look like this in main.cf:

virtual_maps = hash:/etc/postfix/virtual, regexp:/etc/postfix/virtual-regexp 

Build the mapfile by typing:

postmap /etc/postfix/virtual-regexp 

This also requires a virtual.db to exist.

If it doesn’t create an empty file called virtual:

touch /etc/postfix/virtual

Then run the following to add the mapping

postmap /etc/postfix/virtual

Then just restart postfix!

/etc/init.d/postfix restart

Leave a Reply