Ubuntu – configure postfix to catch all email for all domain and forward to local user

postfixUbuntu

I'd like to configure Postfix (on Ubuntu) to catch all email for all domain and store them locally.

I'd use it for testing. The application under test sends emails to random addresses (abc@abc.com, def@other.tv, and so on), and I'd like to check these emails locally (thunderbird).

I already now that the following in main.cf forwards anyuser@mydestination to localuser:

local_recipient_maps=
luser_relay = localuser

But I'd like to forward anyuser@anydomain to localuser too.

What is the simplest Postfix configuration for this?

Thank you!

Best Answer

This is a good start! While there might be other ways, I'll continue from where you have started, i.e.

local_recipient_maps =
luser_relay = localuser

In this sitation you only need to make all domais handled as if they were in $mydestination.

Overriding Postfix's built-in default transport:nexthop selection is possible by using transport maps:

transport_maps (default: empty)

Optional lookup tables with mappings from recipient address to (message delivery transport, next-hop destination). See transport(5) for details.

Specify zero or more type:table lookup tables, separated by whitespace or comma. Tables will be searched in the specified order until a match is found. If you use this feature with local files, run postmap /etc/postfix/transport after making a change.

In your main.cf, add transport_maps = hash:/etc/postfix/transport.

In /etc/postfix/transport you combine these two:

  • local_transport (default: local:$myhostname)

    This is the default for final delivery to domains listed with mydestination, and for [ipaddress] destinations that match $inet_interfaces or $proxy_interfaces. The default nexthop destination is the MTA hostname.

  • * transport:nexthop

    The special pattern * represents any address (i.e. it functions as the wildcard pattern, and is unique to Postfix transport tables).

Resulting: * local:$myhostname

Please keep this unconventional configuration inside your lab.

Related Topic