Create a gist now

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.


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


@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!


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


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


Good question - I'm seeing the same error.

Appropriate entries in
mydomain_fallback = localhost

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.


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.


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.


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


@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


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)

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?


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

marr commented Jun 4, 2015

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

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
pelly commented Sep 15, 2015

Wanted to echo that the

smtp_sasl_mechanism_filter = login

worked for me on Yosemite (just upgraded)


@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.

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.

cybercussion commented Jul 11, 2016 edited

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'.


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?

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.

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