1

How can I release outgoing mail to the internet if local delivery fails in postfix?

My server has virtual domains configured with mydomain.tld. When I send an email to [email protected] it try to deliver locally and fails if user not found. Instead of that I need to release those mails to the internet.

Reason for above requirement is I have multiple servers configured with mydomain.tld. Different users are in different servers but same domain - mydomain.tld (I have a working mechanism for incoming mails)

This is my main.cf file.

# postfix config file

# uncomment for debugging if needed
# soft_bounce=yes

# postfix main
mail_owner = postfix
setgid_group = postdrop
delay_warning_time = 4

# postfix paths
html_directory = no
command_directory = /usr/sbin
daemon_directory = /usr/lib/postfix
queue_directory = /var/spool/postfix
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.2.2/samples
readme_directory = /usr/share/doc/postfix-2.2.2/README_FILES

# network settings
inet_interfaces = all
mydomain   = mail1.mydomain.com
myhostname = mail1.mydomain.com
mynetworks = all
mydestination = localhost.$mydomain, localhost
#relay_domains = proxy:mysql:/etc/configs/postfix/mysql-relay_domains_maps.cf

# mail delivery
recipient_delimiter = +

# mappings
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
#transport_maps = hash:/etc/postfix/transport
#local_recipient_maps =
#local_transport = error:local mail delivery is disabled

# virtual setup
virtual_alias_maps = proxy:mysql:/etc/configs/postfix/mysql-virtual_alias_maps.cf,
                     regexp:/etc/configs/postfix/virtual_regexp
virtual_mailbox_base = /var/vmail
virtual_mailbox_domains = proxy:mysql:/etc/configs/postfix/mysql-virtual_domains_maps.cf
virtual_mailbox_maps = proxy:mysql:/etc/configs/postfix/mysql-virtual_mailbox_maps.cf
virtual_mailbox_limit_maps = proxy:mysql:/etc/configs/postfix/mysql-virtual_mailbox_limit_maps.cf
virtual_minimum_uid = 150
virtual_uid_maps = static:150
virtual_gid_maps = static:8
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1

# debugging
debug_peer_level = 2
debugger_command =
         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
         xxgdb $daemon_directory/$process_name $process_id & sleep 5

# authentication
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
broken_sasl_auth_clients = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth

# tls config
smtp_use_tls = no
smtpd_use_tls = no
#smtp_tls_note_starttls_offer = yes
#smtpd_tls_loglevel = 1
#smtpd_tls_received_header = yes
#smtpd_tls_session_cache_timeout = 3600s
#tls_random_source = dev:/dev/urandom
#smtp_tls_session_cache_database = btree:$data_directory/smtp_tls_session_cache
# Change mail.example.com.* to your host name
#smtpd_tls_key_file = /etc/pki/tls/private/mail.example.com.key
#smtpd_tls_cert_file = /etc/pki/tls/certs/mail.example.com.crt
# smtpd_tls_CAfile = /etc/pki/tls/root.crt

# rules restrictions
smtpd_client_restrictions =
smtpd_helo_restrictions =
smtpd_sender_restrictions =
smtpd_recipient_restrictions = permit_sasl_authenticated,
        permit_mynetworks,
        reject_unauth_destination,
        reject_non_fqdn_sender,
        reject_non_fqdn_recipient,
        reject_unknown_recipient_domain
# uncomment for realtime black list checks
#       ,reject_rbl_client zen.spamhaus.org
#       ,reject_rbl_client bl.spamcop.net
#       ,reject_rbl_client dnsbl.sorbs.net

smtpd_helo_required = yes
unknown_local_recipient_reject_code = 550
disable_vrfy_command = yes
smtpd_data_restrictions = reject_unauth_pipelining

Thanks for any answers in advance.

6
  • 1
  • I'm still thinking there should be a way to do this. Postfix is a pretty advanced application. It's a shame if it can't do something like this simple?
    – M_R_K
    Oct 29, 2014 at 3:51
  • There is ugly workaround involving postfix multi_instance, smtp_fallback_relay and smtp_reply_filter. Unfortunately, I haven't tested it [ too busy right now :) ].
    – tpml7
    Oct 29, 2014 at 4:31
  • What do you mean by "Instead of that I need to release those mails to the internet. " ?
    – mc0e
    Oct 29, 2014 at 10:41
  • Server deliver all the emails fine except my own domain. If user exist in the same server it also deliver fine. But [email protected] may be in another server. So I need to let emails to lookup mx and find the delivery path itself if local delivery fails. I hope this make sense. Thanks
    – M_R_K
    Oct 29, 2014 at 11:21

1 Answer 1

4

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .