MacOS – How to send email from OS X command line

command lineemailgmailhomebrewmacos

Dozens of tutorials followed and nothing works.

msmtp doesn't work ("TLS certificate verification failed: unable to get local issuer certificate" (cert installed)

postfix doesn't work (no way to specify from address)

aws ses doesn't work (unverified email (that's verified))

mutt and mailx tried every combination with the above.

Comcast and Gmail services tried with the above…

Assuming a bone clean install of El Capitan with Homebrew. Blue sky, spare no expense (I'll buy a service that actually works at this point.)

I need to send an email from the command line.

Best Answer

Sendemail works great with Gmail and all other SMTP servers I have ever tried:

brew update
brew install sendemail
man sendemail

Edit: Thanks for the edit/link/clarification, @patrick.

I also wanted to clarify that I have always used sendemail flawlessly on Debian-based systems, but encountered TLS error after upgrading from OS X Mountain Lion to Mavericks when Mavericks was first released. I don't recall if I even tried to uninstall/re-install from a "Mavericks bottle", but I believe the problem actually had to do with Google updating their accepted handshake protocols or whatnot around this time.

The fix was easily-found by Googling and involved editing a line in the sendemail config to [I believe] remove a reference to SSL and replace it with TLS 1.1 (or something of the sort).

I'm sure sendemail itself has been upgraded since then to account for this, because I believe I have used it successfully since then on both OS X Yosemite and El Capitan with Gmail without having to make any weird modifications to the configuration.

It truly is a great program, and I cannot give it enough praises. If any of you are familiar with blat for Windows, sendemail is like that, except much more powerful and very easy to use.