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/main.cf

sudo vim /etc/postfix/main.cf

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

myhostname = smtp.gmail.com

.
.
.

# SASL SUPPORT FOR SERVERS
#
# The following options set parameters needed by Postfix to enable
# Cyrus-SASL support for authentication of mail servers.
#
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_use_tls = yes

Create a sasl_passwd if one doesn't exist

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

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

tree /var/www/somefolder | mail -s "contents" your@yourdomain.com

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]@gmail.com from an app that doesn't meet modern security standards.

is to enable less secure apps on your account: https://www.google.com/settings/security/lesssecureapps. Do this at your own discretion.

@wouterds

This comment has been minimized.

Show comment Hide comment
@wouterds

wouterds Jan 29, 2014

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

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

@larrybotha

This comment has been minimized.

Show comment Hide comment
@larrybotha

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

Owner

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!

@wouterds

This comment has been minimized.

Show comment Hide comment
@wouterds

wouterds Jan 31, 2014

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

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

@wealthychef1

This comment has been minimized.

Show comment Hide comment
@wealthychef1

wealthychef1 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 smtp.comcast.net[76.96.40.155]: no mechanism available

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

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 smtp.comcast.net[76.96.40.155]: no mechanism available

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

This comment has been minimized.

Show comment Hide comment
@ghost

ghost Aug 19, 2014

Good question - I'm seeing the same error.

Appropriate entries in main.cf:
mydomain_fallback = localhost
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

ghost commented Aug 19, 2014

Good question - I'm seeing the same error.

Appropriate entries in main.cf:
mydomain_fallback = localhost
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

@Jaace

This comment has been minimized.

Show comment Hide comment
@Jaace

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

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.

@larrybotha

This comment has been minimized.

Show comment Hide comment
@larrybotha

larrybotha Sep 17, 2014

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

@lifereimagined try putting brackets around the gmail subdomain:

relayhost=[smtp.gmail.com]:587

Additionally, I don't have smtp_tls_security_level=encrypt in my main.cf, 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.

Owner

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:

relayhost=[smtp.gmail.com]:587

Additionally, I don't have smtp_tls_security_level=encrypt in my main.cf, 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.

@pjotrsavitski

This comment has been minimized.

Show comment Hide comment
@pjotrsavitski

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

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.

@larrybotha

This comment has been minimized.

Show comment Hide comment
@larrybotha

larrybotha Nov 12, 2014

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

Owner

larrybotha commented Nov 12, 2014

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

@null9beta

This comment has been minimized.

Show comment Hide comment
@null9beta

null9beta 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

@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

@senorgeno

This comment has been minimized.

Show comment Hide comment
@senorgeno

senorgeno 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)

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)

This comment has been minimized.

Show comment Hide comment
@ghost

ghost 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?

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?

@twodayslate

This comment has been minimized.

Show comment Hide comment
@twodayslate

twodayslate 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

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

This comment has been minimized.

Show comment Hide comment
@marr

marr Jun 4, 2015

send-mail: fatal: myhostname and relayhost parameter settings must not be identical: smtp.gmail.com

marr commented Jun 4, 2015

send-mail: fatal: myhostname and relayhost parameter settings must not be identical: smtp.gmail.com

@n0mer

This comment has been minimized.

Show comment Hide comment
@n0mer

n0mer Jul 27, 2015

this advice came handy: http://stackoverflow.com/questions/26447316/mac-os-x-10-10-yosemite-postfix-sasl-authentication-failed

It turned out I was missing the following line in /etc/postfix/main.cf:

smtp_sasl_mechanism_filter = plain

n0mer commented Jul 27, 2015

this advice came handy: http://stackoverflow.com/questions/26447316/mac-os-x-10-10-yosemite-postfix-sasl-authentication-failed

It turned out I was missing the following line in /etc/postfix/main.cf:

smtp_sasl_mechanism_filter = plain
@pelly

This comment has been minimized.

Show comment Hide comment
@pelly

pelly Sep 15, 2015

Wanted to echo that the

smtp_sasl_mechanism_filter = login

worked for me on Yosemite (just upgraded)

pelly commented Sep 15, 2015

Wanted to echo that the

smtp_sasl_mechanism_filter = login

worked for me on Yosemite (just upgraded)

@lacostenycoder

This comment has been minimized.

Show comment Hide comment
@lacostenycoder

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

@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

This comment has been minimized.

Show comment Hide comment
@roubles

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

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

This comment has been minimized.

Show comment Hide comment
@cybercussion

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

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

@HolyGraal

This comment has been minimized.

Show comment Hide comment
@HolyGraal

HolyGraal 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]@smtp.gmail.com (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]@gmail.com:[password]
So, why it trying to send mail using my mac user @ smtp.gmail.com ? I think that may be the issue?? How do I fix this?

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]@smtp.gmail.com (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]@gmail.com:[password]
So, why it trying to send mail using my mac user @ smtp.gmail.com ? I think that may be the issue?? How do I fix this?

@lvlaxpt

This comment has been minimized.

Show comment Hide comment
@lvlaxpt

lvlaxpt Apr 19, 2017

sudo nano /etc/postfix/main.cf

add below configs

mydomain_fallback = localhost
mail_owner = _postfix
setgid_group = _postdrop
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_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

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

then send email

date | mail -s test test@yahoo.com

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.

lvlaxpt commented Apr 19, 2017

sudo nano /etc/postfix/main.cf

add below configs

mydomain_fallback = localhost
mail_owner = _postfix
setgid_group = _postdrop
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_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

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

then send email

date | mail -s test test@yahoo.com

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.

@ranelpadon

This comment has been minimized.

Show comment Hide comment
@ranelpadon

ranelpadon Jun 9, 2017

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

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

@hauleth

This comment has been minimized.

Show comment Hide comment
@hauleth

hauleth Dec 2, 2017

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

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.

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