Relase outgoing mails to internet if local delivery failes

Solution 1:

I would suggest that you to remove all the virtual_mailbox_* parameter and use only transport_maps and relay_domains.

Set up a "dovecot:" transport in master.cf which delivers your mails via the dovecot LDA or the dovecot LMTP. E.g.:

dovecot   unix  -       n       n       -       -       pipe
    flags=DRhu user=vmail:vmail argv=/usr/local/libexec/dovecot/dovecot-lda -f ${sender} -d ${recipient}

The next action is to append mydomain.tld to your relay_domains.

After that configure a SQL config file for the transport_maps to give you a result like "dovecot:" for each existing user. Otherwise don't return anything here. Also create a hash table for transport_maps with the following entry:

mydomain.tld    [other.mailserver.mydomain.tld]

The last line would be your default relayhost for mydomain.tld. Any matching email address overwrites this default and is therefore delivered to your local dovecot server.