The following configuration has been performed in Debian but should apply in any Linux distro with Postfix installation. The task quite simple: use Gmail as SMTP relay for outgoing email traffic.
1) At first place I had to install the following packages and turn off sendmail:
apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules service sendmail stop
2) Then edit the configuration file at /etc/postfix/main.cf by adding the following options at the end of the file:
# Gmail SMTP relay relayhost = [smtp.gmail.com]:587 smtp_use_tls=yes smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt smtp_sasl_security_options =
3) Create the authentication file at /etc/postfix/sasl_passwd and set the right permissions:
[smtp.gmail.com]:587 <username>@gmail.com:<password> chmod 400 /etc/postfix/sasl_passwd
Make sure the file is owned by the user who runs the Postfix daemon.
4) Reload Postfix:
service postfix reload
5) Confirm the configuration is actually working by sending a test mail:
echo "Test mail from postfix" | mail -s "Test Postfix" email@example.com
The sender of the email should be the given Gmail account. Also, in the “Sent” folder of the Gmail account you should see the email you have sent with Postfix.
If your domain is using Gmail’s infrastructure for handling emails, you can replace @gmail.com with your domain and use the corresponding account details.
NOTE: This configuration will be sending any system message as “firstname.lastname@example.org” and therefore is not advised to be used in multi-user environment.