Skip to content

Instantly share code, notes, and snippets.

@kany
Last active June 3, 2024 20:13
Show Gist options
  • Save kany/c44c077881047ead8faa to your computer and use it in GitHub Desktop.
Save kany/c44c077881047ead8faa to your computer and use it in GitHub Desktop.
Setup SENDMAIL on Mac OSX Yosemite

SENDMAIL on MAC OSX Yosemite

  1. Create a file to store our credentials:
sudo vim /etc/postfix/sasl_passwd
  1. Add something like this:
smtp.gmail.com:587 username@gmail.com:password
  1. Now run:
sudo postmap /etc/postfix/sasl_passwd
  1. Prepare the postfix main config file:
sudo vim /etc/postfix/main.cf
  1. Add/update these lines
    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
    smtp_sasl_security_options = noanonymous
    smtp_always_send_ehlo = yes
    smtp_sasl_mechanism_filter = plain
  1. Stop/Start the service
sudo postfix stop && sudo postfix start
  1. Check the queue for any errors
mailq
@privaloops
Copy link

simple and works, thx

@welps
Copy link

welps commented Apr 10, 2016

This worked great for me too, thanks!

@crowmagnumb
Copy link

Awesome. Thanks! One small thing. If postfix is not running, which it was not for me, then your shortcut
sudo postfix stop && sudo postfix start
fails to run the second half. So two lines would be suggested here.
sudo postfix stop
sudo postfix start

@lebensterben
Copy link

@crowmagnumb Your modification works for me and fixed my problem. Thx.

@juwul
Copy link

juwul commented Nov 9, 2017

Seems like a great guide, but I'm having problems with the TSL configuration and have been trying to for hours now. Anyone getting;
TLS is required, but our TLS engine is unavailable
When using mailq after following above guide?

@giovanigenerali
Copy link

giovanigenerali commented Nov 10, 2017

I'm also having the same problem with the TLS
(TLS is required, but our TLS engine is unavailable)
Anyone have a fix about it? Tks

@giovanigenerali
Copy link

@juwul I found how to fix here http://www.postfix.org/TLS_README.html#built-in

Enable tls:

sudo postfix tls enable-client

Reload:

sudo postfix reload

@hannesa2
Copy link

I run into postqueue: fatal: Queue report unavailable - mail system is down
after I run sudo postconf compatibility_level=2 and sudo postfix reload sudo postfix start

mailq is now working

@irojus
Copy link

irojus commented Apr 23, 2018

If you are using gmail don't forget to enable "Less secure apps" - https://support.google.com/accounts/answer/6010255

@sunilbreddy
Copy link

sunilbreddy commented May 29, 2018

Got below error message. Can someone help?
unknown: fatal: relayhost parameter setting must not contain multiple values: 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 smtp_sasl_security_options = noanonymous smtp_always_send_ehlo = yes smtp_sasl_mechanism_filter = plain

@isaacavery
Copy link

@sunilbreddy, you need to put each parameter on a separate line. Just replace the space before each parameter with a line break, like so:

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
smtp_sasl_security_options = noanonymous
smtp_always_send_ehlo = yes
smtp_sasl_mechanism_filter = plain

@thanhnd2812
Copy link

Thanks! It's working on my end but I have a little issue:

I've set: smtp.gmail.com:587 username@gmail.com:password in sasl_passwd and can send emails and all my emails sender address is username@gmail.com.

I want to replace username@gmail.com by user entered email. How can I get it?

Thanks in advance.

@mxvsh
Copy link

mxvsh commented Sep 11, 2019

I am getting this error: postfix/postfix-script: fatal: the Postfix mail system is not running

@kany
Copy link
Author

kany commented Sep 11, 2019

I apologize for not responding to anyone. I've never received a notification until now.

@thedevxen I hope this helps. Check this out:
https://serverfault.com/questions/816113/postfix-postfix-script-fatal-the-postfix-mail-system-is-not-running

@mxvsh
Copy link

mxvsh commented Sep 11, 2019

I apologize for not responding to anyone. I've never received a notification until now.

@thedevxen I hope this helps. Check this out:
https://serverfault.com/questions/816113/postfix-postfix-script-fatal-the-postfix-mail-system-is-not-running

Sorry, but I am not using "Server app" as asked in that question.

@kany
Copy link
Author

kany commented Sep 11, 2019

@thedevxen

Try this then restart the service. I hope this helps. If not, I'll try digging into later.

postconf compatibility_level=2

https://apple.stackexchange.com/questions/355986/configuring-and-running-postfix-mojave-10-14-4

@rdermer
Copy link

rdermer commented Apr 18, 2020

Thanks for this - it was really helpful. Took a bit and eventually I got sendmail to work. For my ISP things didn't work until I added to /etc/postfix/main.cf - sendmail didn't want to connect using the resolved IPV6 addr.

net_protocols=ipv4

I also added this (not sure if this was needed -- the default value was loopback-only which looked suspicious).

inet_interfaces = all

For my google account I have 2FA enabled and needed an application specific password in /etc/postfix/sasl_passwd see https://support.google.com/accounts/answer/185833

Hope that helps someone else in getting this working.

@ivan-gloginjic
Copy link

Works :-) thanks

@kingnight
Copy link

I also have the problem TLS is required, but our TLS engine is unavailable, then modify sudo vim /etc/postfix/main.cf change
smtp_tls_security_level=none,problem fix

@ddaddy
Copy link

ddaddy commented Feb 19, 2021

I'm having issues with Xcode server bot sending emails. I get these logs:

kernel    Sandbox: sendmail(48548) deny(1) forbidden-exec-sugid
sendmail    fatal: execvp /usr/sbin/postdrop: Operation not permitted
sendmail    warning: command "/usr/sbin/postdrop -r" exited with status 1
sendmail    fatal: xcode@<redacted>.com(450): unable to execute /usr/sbin/postdrop -r: Undefined error: 0

Possibly a user issue? Anyone got any ideas?

@ddaddy
Copy link

ddaddy commented Feb 19, 2021

Yes. Unfortunately it seems on Big Sur it's not possible to amend the permissions chown: /usr/libexec/postfix: Operation not permitted as the root is now readonly.

@TonReurts
Copy link

TonReurts commented Nov 28, 2022

After this setup I get the following error:
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
0B3D68C4939 1669 Mon Nov 28 11:31:59 imac2019@iMac-di-iMac.fritz.box
(Temporary lookup error)
ton@reurts.com
What setting have I done wrong?

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