DevHeads.net

How to act based on the interface on which the mail was received?

Hi.

I have this postfix instance to relay all mail to a relay host but I wish to make this instance also an archiving MX for a domain. Initially the configuration was:

mynetworks = 127.0.0.0/8
mailbox_size_limit = 0
inet_interfaces = loopback-only
inet_protocols = ipv4
myhostname = domain.com
mydestination =
biff = no
append_dot_mydomain = no
soft_bounce = yes
relayhost = ***************
smtp_sasl_password_maps = ***************
smtp_use_tls=yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
smtp_tls_CAfile=/etc/ssl/certs/ca-certificates.crt
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
compatibility_level=2

In order to make it accept mail for a domain for archiving from the primary mail server, I removed the inet_interfaces so that it listens to public interface also and then configured the domain:

mynetworks = 127.0.0.0/8
mailbox_size_limit = 0
inet_protocols = ipv4
myhostname = domain.com
mydestination =
biff = no
append_dot_mydomain = no
soft_bounce = yes
relayhost = ***************
smtp_sasl_password_maps = ***************
smtp_use_tls=yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
smtp_tls_CAfile=/etc/ssl/certs/ca-certificates.crt
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
compatibility_level=2
#
#
virtual_mailbox_domains = domain.com
virtual_mailbox_base = /home/archive
virtual_mailbox_maps = static:mail/
virtual_uid_maps = static:1000
virtual_gid_maps = static:1000

But now even locally generated email for domain.com was getting stored in the virtual mailbox instead of getting relayed to the relayhost. So made virtual_mailbox_domains= empty in main.cf and configured public interface separately in master.cf:

mynetworks = 127.0.0.0/8
mailbox_size_limit = 0
inet_protocols = ipv4
myhostname = domain.com
mydestination =
biff = no
append_dot_mydomain = no
soft_bounce = yes
relayhost = ***************
smtp_sasl_password_maps = ***************
smtp_use_tls=yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
smtp_tls_CAfile=/etc/ssl/certs/ca-certificates.crt
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
compatibility_level=2
#
#
virtual_mailbox_domains =
virtual_mailbox_base = /home/archive
virtual_mailbox_maps = static:mail/
virtual_uid_maps = static:1000
virtual_gid_maps = static:1000

master.cf:

xx.xx.x.x:smtp inet n - y - - smtpd -o virtual_mailbox_domains=domain.com
127.0.0.1:smtp inet n - y - - smtpd

But this isn't working. The server is refusing to accept mail for domain.com on the public interface. In other words, how do I override virtual_mailbox_domains for the public IP? I wish to relay all locally generated emails to smarthost but store the email received on public IP for this domain.

Thanks.