Dropping sendmail-postfix for msmtp

Apple OS X 10.8 Server.app was the worst move I ever made. The mail server issues in 10.8 Server.app were well known and I was too impatient to wait for fixes at the time of it’s launch. I’m used to running at the low level of the unix core, configuring mail servers and web servers manually so when I went to the GUI goodness of Server.app I was, to say the least, out of my element. I couldn’t leave the manual settings alone, while Server.app insisted on re-managing things for me. Add to that, every Server.app update tended to break things I’d previously configured.

I played this cat and mouse game with Server.app until finally any combination mail, postfix and sendmail was completely broken. Short of a clean install I was dead in the water as far as a mail server was concerned. Even the techs at Apple had no advice.

Having been a fan of msmtp on my Linux servers I figured, why not. Homebrew to the rescue…

  1. Install msmtp via homebrew (Terminal) [NOTE: Don’t have Homebrew?]:
    $ brew install msmtp --with-macosx-keyring
  2. Create or edit your ~/.mailrc to include:
    set sendmail=/usr/local/bin/msmtp
  3. Create or edit your ~/.msmtprc to include (replace with your credentials):
    # Example for a user configuration file
    # Set default values for all following accounts.
    tls on
    logfile ~/.msmtp.log
    # A gmail service
    account example@gmail.com
    host smtp.gmail.com
    port 587
    protocol smtp
    auth on
    from example@gmail.com
    user example@gmail.com
    tls on
    tls_starttls on
    # Your mac should have certificates in /etc/certificates/
    # Pick one, if it doesn't work, try another one.
    # If you have no certicicates there then Google it.
    tls_trust_file /etc/certificates/Server Fallback SSL Certificate.5522E4EEF50C3C50FC549364EA761E7E3C4C3503.cert.pem
    # Set a default account
    # You need to set a default account for Mail
    account default : example@gmail.com
  4. Give your ~/.msmtprc the right permissions (Terminal):
    $ chmod 0600 ~/.msmtprc
  5. Create a new password item in Keychain Access (Keychain Access > File > New Password Item) with the following data (replace with your credentials):
    Keychain Item Name: smtp://smtp.gmail.com
    Account name: example@gmail.com
    Password: secret
  6. To test, run the following command (Terminal) [NOTE: click “Allways allow when the Keychain authorization request pops up”]:
    $ echo "Hello world" | Mail -s "msmtp test at `date`" someother@gmail.com

SOURCES: msmtp, a free tool to send email from Terminal, send eBooks to your kindle, Use Mutt with Gmail