28

To create a test email server, I have a similar requirement as:

How to redirect all outgoing email from postfix to a single address for testing

But I need to send all the emails to an external account, not a local one.

I would like to do something like:

  • xyz:email@gmail.com

but xyz is not local nor smtp.

user43856
  • 281

3 Answers3

55

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

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

Edit /etc/postfix/main.cf and add the file to virtual_alias_maps. The end result might look like this:

virtual_alias_maps = regexp:/etc/postfix/virtual-regexp

If you had existing virtual_alias_maps, separate the values with commas (eg. virtual_alias_maps = hash:/etc/postfix/virtual, regexp:/etc/postfix/virtual-regexp).

Build the mapfile by typing:

postmap /etc/postfix/virtual-regexp

Then restart postfix :

sudo service postfix restart

Voila!

BlueRaja
  • 1,346
  • 1
  • 13
  • 18
3

As this took me some time:

If you want to exclude target domains from this, prefix the rule with

/.+@exclude1.com/ @exclude1.com
/.+@exclude2.com/ @exclude2.com
...

to preserve original recipient, i found the virtual manpage a bit confusing on how to achive this.

-4

Is it acceptable to just have it go to a local account that then forward all mail to your external address? You could get it running like the other question you mentioned, and then use procmail to have the messages forwarded and then deleted locally. Something like this would probably do the trick by replacing the folder with /dev/null.

Paul Kroon
  • 2,280
  • 1
  • 16
  • 20