I finally managed to figure this out using various guides I found.
Here's my notes.
First, I created a new Gmail account with an appropriate name to use as my SMTP relay.
I already had Postfix installed on a Ubuntu Server but configured to deliver local mail only so I started by reconfiguring it for 'Internet with smarthost'.
Code:
dpkg-reconfigure postfix
Once complete I had to add a few extra settings to /etc/postfix/main.cf to enable TLS and SASL authentication.
Code:
postconf -e 'relayhost = smtp.gmail.com:587'
postconf -e 'smtp_use_tls = yes'
postconf -e 'smtp_sasl_auth_enable = yes'
postconf -e 'smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd'
postconf -e 'smtp_sasl_security_options = no'
postconf -e 'smtp_sasl_security_options = noanonymous'
postconf -e 'smtp_sasl_tls_security_options = noanonymous'
postconf -e 'smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt'
I then created a hashed password file with my Gmail accounts login details. You can use an application specific password here if you have two factor authentication enabled on the account.
Code:
echo 'smtp.gmail.com:587 <user>@gmail.com:<password>' > /etc/postfix/sasl_passwd
postmap hash:/etc/postfix/sasl_passwd
rm /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd.db
From here there are various options for forwarding mail to your desired email address. I already had all root mail sent to my user account via /etc/aliases. I could have altered this but I simply created a .forward file in my home directory and that's how it's stayed.
That's it, I now have all system mail sent to my personal email account and I can enable mail functions in the web applications on the server.
Some useful links:
Day in my life: Postfix smarthost with SMTP authentication
Setup postfix using an authorized relay host (Gmail) for RHEL/CentOS | stigmatedbrain's corner
braiden.org » Blog Archive » Using gmail as a Postfix Smarthost
Configure Postfix to Use Gmail SMTP on Ubuntu