Table of Contents

Mail Server#MTA (mail transfer agent)

Postfix Relay Configurations


Postfix Commands and Configuration Examples



General relay

From Trusted network, Any Destination

mynetworks = 192.168.0.0/16, 127.0.0.0/8


From UnTrusted network, Relay Permit Destination

myhostname = smtp.example.com
mydomain = example.com
mydestination = $myhostname, localhost.$mydomain, localhost
relay_domains = $mydestination, test1.com, test2.com


Relay a specific email address to another server

Method1. Create mail aliases in /etc/aliases

/etc/aliases
user1: user1@example.com



reflect /etc/aliases

# newaliases


Method2. .forward setting of mail forwarding

~/.forward (/home/user1/.forward)

Forward all emails and do not leave the original email

test@example.com



Forward all emails and leave the original email

\user1
test@example.com




Relay email addresses for a particular domain to another server

/etc/postfix/main.cf
relay_domains = example.com, example.jp
transport_maps = hash:/etc/postfix/transport
/etc/postfix/transport
example.com     smtp:[x.x.x.x]
example.jp      smtp:[x.x.x.x]
Reflect settings
postmap  hash:/etc/postfix/transport
systemctl reload postfix




Change delivery destination by sender(From:)

You can use sender_dependent_default_transport_maps or sender_dependent_relayhost_maps.

Method1. sender_dependent_default_transport_maps

/etc/postfix/main.cf
sender_dependent_default_transport_maps = hash:/etc/postfix/sender_dependent_transport
/etc/postfix/sender_dependent_transport
@example.com        stmp:[x.x.x.x]:25
@sub.example.com    stmp:[x.x.x.x]:25


Method2. sender_dependent_relayhost_maps

Overridden in transport table

/etc/postfix/main.cf
sender_dependent_relayhost_maps = hash:/etc/postfix/sender_dependent_relayhost
/etc/postfix/sender_dependent_relayhost
@example.com        [x.x.x.x]:25
@sub.example.com    [x.x.x.x]:25