Suppose you want all your web servers to locally send all email to a smtp gateway and you are running Postfix as your MTA,

In your main.cf file (usually /etc/postfix/main.cf or /usr/local/etc/postfix/main.cf), specify your transport maps:

transport_maps = hash:/etc/postfix/transport

And in your transport file (usually /etc/postfix/transport or /usr/local/etc/postfix/transport), specify your gateways per domain.

This allows you to specify with regular expressions which emails go where.

In this case, for instance using a wildcard to make every domain to get forwarded:

*   smtp:myrelayrhost.com

Then invoke postmap to regenerate the transports db, and reload postfix:

# postmap hash:/etc/postfix/transport

# postfix reload

And that’s it!

All email generated in this host should now be forwarded to the SMTP gateway.

Remember to configure your SMTP gateway to accept mail from all the hosts that will forward emails to it.