Set gmail username and password.
sudo vi /etc/postfix/sasl_passwd
Enter username and password using the following format: [smtp.gmail.com]:587 [email protected]:PASSWORD
Update changes:
sudo postmap /etc/postfix/sasl_passwd
Update postfix configuration.
sudo vi /etc/postfix/main.cf
Add this at end of file:
# Gmail SMTP relay
relayhost = [smtp.gmail.com]:587
# Enable SASL authentication in the Postfix SMTP client.
smtpd_sasl_auth_enable = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =
smtp_sasl_mechanism_filter = AUTH LOGIN
# Enable Transport Layer Security (TLS), i.e. SSL.
smtp_use_tls = yes
smtp_tls_security_level = encrypt
tls_random_source = dev:/dev/urandom
Restart postfix service and test mail.
sudo postfix stop
sudo postfix start
date | mail -s "Test Email" [email protected]
When using Gmail, remember to enable less secure apps at https://myaccount.google.com/lesssecureapps. Could be a good thing to disable this again after testing. :)