Skip to content

Instantly share code, notes, and snippets.

@thecontinium
Forked from giovanigenerali/postfix-gmail-macos.md
Last active January 20, 2019 09:09
Show Gist options
  • Select an option

  • Save thecontinium/353f2a4100cb6ac534470bb0defb834c to your computer and use it in GitHub Desktop.

Select an option

Save thecontinium/353f2a4100cb6ac534470bb0defb834c to your computer and use it in GitHub Desktop.
Postfix Gmail relay on macOS Sierra & macOSHigh Sierra

Postfix Gmail relay on macOS Sierra, High Sierra & Mojave

  1. Create a file to store our credentials:
sudo vim /etc/postfix/sasl_passwd
  1. Add something like this with an app password from gmail:
smtp.gmail.com:587 [email protected]:app_password
  1. Now run:
sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
  1. Prepare the postfix main config file:
sudo vim /etc/postfix/main.cf
  1. Add/update these lines after the commented out relayhost list:
relayhost = smtp.gmail.com:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtp_tls_security_level = encrypt
tls_random_source = dev:/dev/urandom
smtp_sasl_security_options = noanonymous
smtp_always_send_ehlo = yes
smtp_sasl_mechanism_filter = plain
  1. Stop/Start the service:
sudo postfix stop && sudo postfix start

or

sudo postfix reload

or

sudo launchctl stop com.apple.postfix.master
sudo launchctl start com.apple.postfix.master
  1. Testing

date | mail -s testing [email protected]

  1. Check the queue for any errors:
mailq

Useful:

  • To see setup use: postconf -n

  • To clear the mail queue: sudo postsuper -d ALL

Troubleshoot problems:

  • If you receive a message like (TLS is required, but our TLS engine is unavailable) enable tls:
sudo postfix tls enable-client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment