Setup Postfix to function as relay host
Setup Postfix to function as relay host with authentication
- Create a password maps file
- You can create multiple entries in the sasl_passwd file for multiple domains
echo "mailserver.example.com username:password" >> /etc/postfix/sasl_passwd chown root:root /etc/postfix/sasl_passwd chmod 600 /etc/postfix/sasl_passwd postmap /etc/postfix/sasl_passwd
- Update /etc/postfix/main.cf
relayhost = mailserver.example.com smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options =
- Restart/Reload postfix
Another Example
Typical configuration for an internal server (inside a LAN) that uses an SMTP server (also internal) to send mail.
Append this to main.cf
mydomain = mail.dev08.example.org myhostname = mail.dev08.example.org myorigin = $mydomain append_dot_mydomain = no relayhost = td006 smtp_host_lookup = native
Below is a configuration diff that was generated from a Ubuntu Trusty default Postfix install as “satellite” server. The server name is ubv10 (as see in diff below). Replace server name throughout the main.cf file. The local server relay is “localsmtp”. Change this as required. Since this is a local server and the name does not feature in the DNS include the smtp_host_lookup
option. If you have a server name that resolves via DNS (as opposed to /etc/hosts), this is not required. Of course make sure /etc/hosts has entry for localsmtp.
diff --git a/postfix/main.cf b/postfix/main.cf index eb619b9..1539d7d 100644 --- a/postfix/main.cf +++ b/postfix/main.cf @@ -33,8 +33,12 @@ alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = /etc/mailname mydestination = ubv10.localdomain, ubv10, localhost.localdomain, localhost -relayhost = smtp.localdomain +relayhost = localsmtp +smtp_host_lookup = native mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = loopback-only
Not exactly sure why, but sometimes it is required to include disable_dns_lookups = yes
along with (or may instead of) smtp_host_lookup = native
when using local (/etc/hosts) host resolution as opposed to DNS (MX record) resolution.
Generic mapping for outgoing SMTP mail
Since the from address will not appear as host.localdomain and be treated as junk mail, to rewrite relayed mail from address use smtp_generic_maps
. Check the below reference.
Reference: http://www.postfix.org/ADDRESS_REWRITING_README.html#generic
Append to main.cf:
# Address rewriting smtp_generic_maps = hash:/etc/postfix/generic
Once updated do hash and reload (as root):
postmap /etc/postfix/generic /etc/init.d/postfix reload