stafwag Blog

staf wagemakers blog

Postfix Smarthost With Authentication

"postfix"

I used the relay host of my internet provider but this was causing issues since my email was getting mark as SPAM in gmail.
 
It was already on my to-do list to move my outgoing mail to my mail provider also to make it easier to move to another ISP or to implement SPF but was not on the top of my to-do list.
 
My email provider requires authentication, so I needed to reconfigure postfix in my FreeBSD mail jail to use a relay host with authentication.

Install postfix-sasl

To use authentication with postfix the postfix-sasl package is required. If postfix is already installed it’ll be replace by postfix-sasl.

1
root@stafmail:/root # pkg install postfix-sasl

Configuration

Update the relay host

main.cf

1
2
3
4
5
6
7
relayhost = [smtp.mailprovider.domain]:465
smtp_use_tls=yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/usr/local/etc/postfix/relay_pass
smtp_sasl_security_options =
smtp_tls_wrappermode = yes
smtp_tls_security_level = encrypt

relay_pass

The credentials are in the relay_pass file the password is in the file as plain-text so we it with the correct file permissions.

1
2
3
root@stafmail:/usr/local/etc/postfix # touch relay_pass
root@stafmail:/usr/local/etc/postfix # chmod 600 relay_pass
root@stafmail:/usr/local/etc/postfix # vi relay_pass
1
[smtp.mailprovider.domain]:465 user:password

Create the hash file.

1
root@stafmail:/usr/local/etc/postfix # postmap relay_pass

Verify the file permissions.

1
2
3
4
root@stafmail:/usr/local/etc/postfix # ls -l relay_pass*
-rw-------  1 root  wheel      60 Feb 23 22:43 relay_pass
-rw-------  1 root  wheel  131072 Feb 23 22:43 relay_pass.db
root@stafmail:/usr/local/etc/postfix # 

Restart

We replaced postfix with postfix-sasl a restart is required.

1
root@stafmail:/usr/local/etc/postfix # /usr/local/etc/rc.d/postfix restart

Have fun

Comments