Running Postfix on Mac (El Capitan) with Gmail 2 step authentication

When testing Drupal on a local machine, it is handy to set up Postfix so that email capability can be tested.

Here's the steps, mostly from , but modified to work with Gmail 2 step authentication.

0. Delete failed email
Just in case there are mails already in the queue, clear the queue, so that any old (failed) mail won't be sent.

sudo postsuper -d ALL

1. Generate Gmail App password
From Google My Account, generate an app password. The usual password for the gmail account doesn't work.

2. Edit /etc/postfix/sasl_passwd

sudo vi /etc/postfix/sasl_passwd

3. Create a postfix lookup
sudo postmap /etc/postfix/sasl_passwd

4. Edit /etc/postfix/
Add the following section to the file.

# Gmail setting
setgid_group = _postdrop
= plain

5. Start postfix or reload
sudo postfix start

If already started, reload the config file.
sudo postfix reload

6. Test to see if email can be sent

echo 'Hello, Tech' | mail -s test

7. Check log if mail is not sent
tail -f /var/log/mail.log

The log shows what is failing.