SASL authentication failed server smtp.gmail.com

Problem

After setting up smtp.gmail.com as relayhost for postfix I stumbled into problem when this showed up in /var/log/mail.log

SASL authentication failed; server smtp.gmail.com
https://accounts.google.com/ContinueSignIn
Please log in via your web browser and then try again.
Learn more at https://support.google.com/mail/bin/answer.py?answer=787

Solution

Allow access to your Google account via
https://accounts.google.com/DisplayUnlockCaptcha

Gmail SMTP server relay with Postfix in Ubuntu 12.04

Tribut to Diogo Esteves http://yaui.me/postfix-gmail-smtp-server-relay-ubuntu/

Prerequisites

$ sudo apt-get install postfix libsasl2-2 libsasl2-modules ca-certificates

Edit /etc/postfix/main.cf

relayhost = [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_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes

Create file /etc/postfix/sasl_passwd

[smtp.gmail.com]:587 user.name@gmail.com:password
$ sudo chmod 400 /etc/postfix/sasl_passwd
$ sudo postmap /etc/postfix/sasl_passwd
$ cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
$ sudo /etc/init.d/postfix reload