Ubuntu: configure postfix as SMTP relay server using Gmail
Install postfix and some tools
Ubuntu: configure postfix to use Gmail as SMTP relay
Install postfix and some toolssudo apt-get install postfix mailutils libsasl2–2 ca-certificates libsasl2-modules
Create the configuration filessudo touch /etc/postfix/main.cf
sudo touch /etc/postfix/sasl_passwd
Paste the following in /etc/postfix/main.cfrelayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CApath = /etc/ssl/certs
smtpd_tls_CApath = /etc/ssl/certs
smtp_use_tls = yes
Paste the following in /etc/postfix/sasl_passwd, replace ‘USERNAME’, ‘PASSWORD’.[smtp.gmail.com]:587 USERNAME@gmail.com:PASSWORD
Correct file permissionssudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
reload postfix for changes to take effectsudo systemctl restart postfix
Test postfix configuration, replace username@gmail.comecho "This is a test :)" | mail -s "host: $(hostname -s) — [THIS IS A TEST]" username@gmail.com