Skip to content

Instantly share code, notes, and snippets.

@angrycub
Created January 2, 2015 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save angrycub/382f1419957c05e73e25 to your computer and use it in GitHub Desktop.
Save angrycub/382f1419957c05e73e25 to your computer and use it in GitHub Desktop.
Configuring PostFix on OSX 10.10

##Configure Postfix for Gmail SMTP## ###Edit file /etc/postfix/main.cf###

sudo vim /etc/postfix/main.cf

and add in the following to the bottom of the file:

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

###Generate sasl_password if not already exists###

sudo vim /etc/postfix/sasl_passwd

and enter in the following:

[smtp.gmail.com]:587 username@gmail.com:password

Run the following commands

sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
sudo launchctl stop org.postfix.master
sudo launchctl start org.postfix.master

And you are done….

###Test your configuration### Now, you should be able to send emails from within the command line e.g. to send the contents of a directory as a tree to an email address

echo "This is a test" | mail -s "Test email from PostFix" your@yourdomain.com
@barrontang
Copy link

failed to config,get the following messages( mailq ):

(connect to smtp.gmail.com[74.125.204.109]:587: Operation timed out)
(connect to smtp.gmail.com[2404:6800:4008:c00::6c]:587: No route to host)
tail -f /var/log/mail.log
Jun 1 22:33:26 applematoMacBook-Pro postfix/smtp[7121]: 58FB377EB6A: SASL authentication failed; server smtp.gmail.com[108.177.97.109] said: 535-5.7.8 Username and Password not accepted. Learn more at?535 5.7.8 https://support.google.com/mail/?p=BadCredentials x30sm6890252pge.23 - gsmtp
Jun 1 22:33:26 applematoMacBook-Pro postfix/smtp[7120]: 056A177EB59: SASL authentication failed; server smtp.gmail.com[108.177.97.108] said: 535-5.7.8 Username and Password not accepted. Learn more at?535 5.7.8 https://support.google.com/mail/?p=BadCredentials m123sm38318421pfc.51 - gsmtp
Jun 1 22:33:28 applematoMacBook-Pro postfix/smtp[7120]: 056A177EB59: SASL authentication failed; server smtp.gmail.com[108.177.97.109] said: 535-5.7.8 Username and Password not accepted. Learn more at?535 5.7.8 https://support.google.com/mail/?p=BadCredentials o20sm33615366pfa.96 - gsmtp
Jun 1 22:33:28 applematoMacBook-Pro postfix/smtp[7120]: connect to smtp.gmail.com[2404:6800:4008:c05::6c]:587: No route to host
Jun 1 22:33:28 applematoMacBook-Pro postfix/smtp[7120]: 056A177EB59: to=barron.tang@gmail.com, relay=none, delay=491, delays=487/0.58/3.5/0, dsn=4.4.1, status=deferred (connect to smtp.gmail.com[2404:6800:4008:c05::6c]:587: No route to host)
Jun 1 22:33:28 applematoMacBook-Pro postfix/smtp[7121]: 58FB377EB6A: to=barron.tang@gmail.com, relay=smtp.gmail.com[108.177.97.108]:587, delay=339, delays=335/0.17/3.5/0, dsn=4.7.8, status=deferred (SASL authentication failed; server smtp.gmail.com[108.177.97.108] said: 535-5.7.8 Username and Password not accepted. Learn more at?535 5.7.8 https://support.google.com/mail/?p=BadCredentials y2sm36900019pfa.65 - gsmtp)

@barrontang
Copy link

Are there any difference between the following:

[smtp.gmail.com]:587 username@gmail.com:password vs. smtp.gmail.com:587 username@gmail.com:password

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