Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Postfix Using Gmail SMTP in Mac OSX Mavericks

Configure Postfix for Gmail SMTP in Mac OSX Mavericks

Taken from Using MacOSX Lion command line mail with Gmail as SMTP

Edit file /etc/postfix/

sudo vim /etc/postfix/

and add in the following below the commented out relayhosts :-

myhostname =


# The following options set parameters needed by Postfix to enable
# Cyrus-SASL support for authentication of mail servers.
relayhost = []:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_use_tls = yes

Create a sasl_passwd if one doesn't exist

sudo vim /etc/postfix/sasl_passwd

and enter in the following:-


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

test by sending the contents of a directory to an email address with the following:

tree /var/www/somefolder | mail -s "contents"

If you receive the following error:

send-mail: fatal: chdir /Library/Server/Mail/Data/spool: No such file or directory

you can do the following:

sudo mkdir -p /Library/Server/Mail/Data/spool
sudo /usr/sbin/postfix set-permissions
sudo /usr/sbin/postfix start

as per this question.

NB: If things aint sending / receiving, and you're getting notices, check that the mail servers you're using are actually working!

NOTE: A crappy way to get around Google's

Someone just tried to sign in to your Google Account [youremail] from an app that doesn't meet modern security standards.

is to enable less secure apps on your account: Do this at your own discretion.

Copy link

wouterds commented Jan 29, 2014

Hmm, doesn't seem to work for me :-(.
(not using gmail, using my own email hosting with SSL on port 465)

Copy link

larrybotha commented Jan 30, 2014

@wouterds ye, I've tried using simple POP email addresses for this configuration and come up empty handed. I've fought with email configurations like a noob for so long I decided to simply settle with using my gmail account :/

Not ideal, but I don't have nightmares about mail configuration anymore!

Copy link

wouterds commented Jan 31, 2014

@larrybotha fixed it with my custom postfix/dovecot mailserver with another tut :)

Copy link

wealthychef1 commented Aug 15, 2014

I've got a maddening error of
Aug 15 14:15:25 RichCookHomeMac postfix/smtp[3191]: warning: SASL authentication failure: No worthy mechs found
Aug 15 14:15:25 RichCookHomeMac postfix/smtp[3191]: AED65298168E: SASL authentication failed; cannot authenticate to server[]: no mechanism available

I have enabled SASL in the and cannot figure out this puppy. Anyone able/willing to help? :-D

Copy link

ghost commented Aug 19, 2014

Good question - I'm seeing the same error.

Appropriate entries in
mydomain_fallback = localhost

Copy link

Jaace commented Sep 4, 2014

This isn't working for me either and I was getting an error at first, which went away when I created the /Library/Server/Mail/Data/spool

I ran this to see if it was correct, and it looks correct...but I'm not really sure:

ps ax | grep postfix
 1818   ??  Ss     0:00.02 /usr/libexec/postfix/master

Now it doesn't complain but nothing is sent to my email account. Mail is so frustrating.

Copy link

larrybotha commented Sep 17, 2014

I really don't know how to resolve any of your errors :/

@lifereimagined try putting brackets around the gmail subdomain:


Additionally, I don't have smtp_tls_security_level=encrypt in my, so that may be something to attempt to remove.

@Jaace, @wealthychef1If you guys come across solutions please post them here - seems like mail on Mac is an issue for many.

Copy link

pjotrsavitski commented Oct 25, 2014

Please note that Yosemite (10.10) requires one more configuration for relay host: smtp_sasl_mechanism_filter

Values of plain or login seem to both work.

Please see stack overflow for more information.

Copy link

larrybotha commented Nov 12, 2014

@pjotrsavitski thanks for the update - will check it out once I move to Yosemite

Copy link

null9beta commented Nov 26, 2014

@pjotrsavitski - wanted to get my postfix up and running again after haven`t used it for some time. I knew that the configuration was working before, your hint made my day

Copy link

senorgeno commented Jan 6, 2015

Hi I needed to enable access from "Less secure apps" with google. Did anyone else have to do this? Otherwise can any help, would rather not take this measure. (I am on Yosemite)

Copy link

ghost commented Mar 4, 2015

Not working for me either. I don't care so much about Gmail though, as I am just trying to setup a mock mail server for local tests. Anyone got this working?

Copy link

twodayslate commented Mar 12, 2015

Not working for me either. I don't have the option to enable "less secure apps" as I am using google apps for your domain

Copy link

marr commented Jun 4, 2015

send-mail: fatal: myhostname and relayhost parameter settings must not be identical:

Copy link

n0mer commented Jul 27, 2015

this advice came handy:

It turned out I was missing the following line in /etc/postfix/

smtp_sasl_mechanism_filter = plain

Copy link

pelly commented Sep 15, 2015

Wanted to echo that the

smtp_sasl_mechanism_filter = login

worked for me on Yosemite (just upgraded)

Copy link

lacostenycoder commented Nov 14, 2015

@pelly did that get around the "Set Less Secure" issue in google accounts? I'm still on Mavericks and can only get this to work if I set less secure access, which kinda blows. My work around was to use a different gmail account that I don't care that much about.

Copy link

roubles commented Jan 28, 2016

It was starting to get painful to do this on all my macs, so I wrote a small script that takes care of all these settings for you.

Copy link

cybercussion commented Jul 11, 2016

So quick question - if you run OS X Server with the Mail option, does it also use Postfix? Or do you use one or the other?
I had it working on Mavericks in 2010, but the latest build I just did in El Capitan was giving me some headaches. 'no route to host' or 'relay access denied'.

Copy link

HolyGraal commented Dec 31, 2016

this is not working. Close. I made some progress. But I am getting mailer daemons using the totally incorrect details here.
It is trying to send mail from [user] (where user is my mac username without the brackets)
I definitely setup my sasl_passwd, and I am using the email in the form of [account][password]
So, why it trying to send mail using my mac user @ ? I think that may be the issue?? How do I fix this?

Copy link

lvlaxpt commented Apr 19, 2017

sudo nano /etc/postfix/

add below configs

mydomain_fallback = localhost
mail_owner = _postfix
setgid_group = _postdrop
relayhost =
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_use_tls = yes
#smtp_tls_security_level = encrypt
#tls_random_source = dev:/dev/urandom
smtp_sasl_mechanism_filter = login

in sasl_passwd

sudo nano /etc/postfix/sasl_passwd

then send email

date | mail -s test

u will receive email from Google with subject "Review blocked sign-in attempt"
from the email you can activate the less secured apps

it works using macos sierra based on above config

hope it helps, as it took me nearly one hour to get it right.

Copy link

ranelpadon commented Jun 9, 2017

Thank you @lvlaxpt. Adding this line: smtp_sasl_mechanism_filter = login in /etc/postfix/ and restarting Postfix to commit the changes, fixed my issue on my macOS Sierra. :)

Copy link

hauleth commented Dec 2, 2017

@lvlaxpt even with your config I am still receiving TLS is required, but our TLS engine is unavailable in mailq.

Copy link

capseaslug commented Jun 3, 2018

Nearly 4 hours later and 4am...and @n0mer you just solved my issue. Here is what I am running that seems to work:

myhostname =
relayhost = []:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/private/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_use_tls = yes
smtp_sasl_mechanism_filter = plain

Copy link

scdn commented Oct 7, 2018

i had issue that postfix is running,but when i send mail ,the username is the my mac had in the sasl_passwd wrote the gmail username) ,then i got the ERROR 5.1.1,who can tell me how to deal with it

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