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

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 http://benjaminrojas.net/configuring-postfix-to-send-mail-from-mac-os-x-... , 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

smtp.gmail.com:587 example@gmail.com:abcdefghijklmnop
?>

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

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

# Gmail setting
setgid_group = _postdrop
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_sasl_mechanism_filter
= plain
smtp_use_tls
=yes
smtp_tls_security_level
=encrypt
?>

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 some-recepient@example.com

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

The log shows what is failing.