Skip to content

Instantly share code, notes, and snippets.

@eivindml
Created August 30, 2017 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eivindml/8b6a3d3512751bc25a57a42f7270a143 to your computer and use it in GitHub Desktop.
Save eivindml/8b6a3d3512751bc25a57a42f7270a143 to your computer and use it in GitHub Desktop.
How to configure postfix mail on macOS, using Gmail.

Instructions

Set gmail username and password.

sudo vi /etc/postfix/sasl_passwd

Enter username and password using the following format: [smtp.gmail.com]:587 EMAIL@gmail.com:PASSWORD

Update changes:

sudo postmap /etc/postfix/sasl_passwd

Update postfix configuration.

sudo vi /etc/postfix/main.cf

Add this at end of file:

# Gmail SMTP relay
relayhost = [smtp.gmail.com]:587

# Enable SASL authentication in the Postfix SMTP client.
smtpd_sasl_auth_enable = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =
smtp_sasl_mechanism_filter = AUTH LOGIN

# Enable Transport Layer Security (TLS), i.e. SSL.
smtp_use_tls = yes
smtp_tls_security_level = encrypt
tls_random_source = dev:/dev/urandom

Restart postfix service and test mail.

sudo postfix stop
sudo postfix start
date | mail -s "Test Email" YOUR_EMAIL@gmail.com

When using Gmail, remember to enable less secure apps at https://myaccount.google.com/lesssecureapps. Could be a good thing to disable this again after testing. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment