Configure Postfix as a mail gateway on Ubuntu

Edit /etc/postfix/main.cf

...

myorigin = /etc/mailname

mydestination =

local_recipient_maps =

local_transport = error:local mail delivery is disabled

virtual_alias_maps = hash:/etc/postfix/virtual

relay_domains = domain1.com domain2.com

parent_domain_matches_subdomains = debug_peer_list smtpd_access_maps

smtpd_relay_restrictions = permit_mynetworks reject_unauth_destination

smtpd_recipient_restrictions =

transport_maps = hash:/etc/postfix/transport

...

Edit /etc/postfix/master.cf to comment local engine

...

retry     unix  -       -       y       -       -       error

discard   unix  -       -       y       -       -       discard

# local     unix  -       n       n       -       -       local

virtual   unix  -       n       n       -       -       virtual

lmtp      unix  -       -       y       -       -       lmtp

...

Create file /etc/postfix/virtual

Create file /etc/postfix/transport

domain1.com       smtp:10.0.224.10

domain2.com       smtp:10.0.218.11

Run postmap

sudo postmap /etc/postfix/virtual

sudo postmap /etc/postfix/transport

Restore Postfix

sudo systemctl restart postfix

Reference:http://www.postfix.org/STANDARD_CONFIGURATION_README.html

Written on November 22, 2016