sudo apt-get update
sudo apt-get install postfix libsasl2-modules -y
###re-configure postfix
dpkg-reconfigure postfix
and choose “Internet-site”
###edit to use sasl
vi /etc/postfix/main.cf
# specify SMTP relay host
relayhost = [mail.isp.example]
# enable SASL authentication
smtp_sasl_auth_enable = yes
# disallow methods that allow anonymous authentication.
smtp_sasl_security_options = noanonymous
# where to find sasl_passwd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
#vi /etc/postfix/sasl_passwd
Add the following line to the new file:
/etc/postfix/sasl_password
smtp.mailgun.org your_mailgun_smtp_user@your_subdomain_for_mailgun:your_mailgun_smtp_password
Next, protect the file by restricting read and write permissions to root and and use the postmap command to update Postfix's lookup tables to use this new file:
#chmod 600 /etc/postfix/sasl_passwd
#postmap /etc/postfix/sasl_passwd
###Restart service postfix
/etc/init.d/postfix restart