How to use transport_map without a existing alias or user in Postfix

postfixsmtp

I'am searching for a way to bypass some accounts to a diffrent Mailserver then postfix. So some accounts should exist on the postfix server but anything else should be transport to a second SMTP Server. For that I setup a new centos 7 and install postfix with yum install postfix. In the defaultconfig I add transport_maps and for a simple test I add example.com in transport_maps with the destination Mailserver. But in case I send a Mail to userX@example.com postfix told me the account doesnet exist.

Postfix only accept Mails for known user so I create a alias in /etc/aliases userX: trash and the Mail will be transport to the destination SMTP Server. My Issue is that I do not know all the aliases from the Destination SMTP Server so I cant add all aliases to aliases.db is there a Option to accept all user on postfix for a known domain?

For a trivial example I need to transport all user to a diffrent SMTP Server.

#postconf -n
alias_database = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5
html_directory = no
inet_interfaces = all
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = $myhostname, example.com
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES
sample_directory = /usr/share/doc/postfix-2.10.1/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
transport_maps = hash:/etc/postfix/transport
unknown_local_recipient_reject_code = 550

And my /etc/postfix/transport looks like:

example.com smtp:smtp.local

UPDATE
As mentioned below I try to solve the issue with fallback_transport. I had updated my main.cf with

fallback_transport = relay
fallback_transport_maps = hash:/etc/postfix/transport

and the content of /etc/postfix/transport is

example.com smtp:smtp.local
*           smtp:smtp.local

but with this config the issue is the same. The user doestn exist so postfix told me the user doesnt exist. If I delete the example.com URL from mydestination the behavior is that the mail to user@example.com is in the mailq

Best Answer

You have to use either fallback_transport or luser_relay.

From: http://www.postfix.org/postconf.5.html

fallback_transport (default: empty)

Optional message delivery transport that the local(8) delivery agent should use for names that are not found in the aliases(5) or UNIX password database.

luser_relay (default: empty)

Optional catch-all destination for unknown local(8) recipients. By default, mail for unknown recipients in domains that match $mydestination, $inet_interfaces or $proxy_interfaces is returned as undeliverable.

To consider:

The precedence of local(8) delivery features from high to low is: aliases, .forward files, mailbox_transport_maps, mailbox_transport, mailbox_command_maps, mailbox_command, home_mailbox, mail_spool_directory, fallback_transport_maps, fallback_transport and luser_relay.