Postfix, Gmail and Mountain Lion Server

What a headache it’s been to get my mail server up and running — consistently — on Mac OS X 10.8! I guess the powers-that-be at Apple felt that it’d be a good idea to shift from /etc/postfix/ to /Library/Server/Mail/Config/postfix/ because… I don’t know, it has a proprietary ring to it perhaps? Who knows? Whatever the case it looks as though the transition was only partially complete, in that not all the paths were written and not all the directories were made.

If you’re like me and you’ve tried to strong arm control back over to /etc/postix then you’ve likely been just as frustrated that every time Apple updates the or serveradmin CLI (now burred deep within the, worth finding and adding to your $PATH) then all your s#!t breaks and you have to go back and do it again. Yeah for Apple Draconianism.

Since I can’t beat them, I might as well join them. So here are the steps to get Gmail piping out messages a la mail/sendmail/postfix from your command line with Mountain Lion 10.8, migrating from configurations in /etc/postfix/ to /Library/Server/Mail/Config/postfix/.


I assume a few things here:

  1. You have installed on your Mac.
  2. You’re comfortable in the command line.
  3. serveradmin have been buried recently. I suggest you add /Applications/ to your $PATH.
  4. When I say “edit such-an-such file”, I assume that you have sudoer privileges and and an editor (VIM, Nano, TextMate, Sublime Text 2, etc…) that can edit these system files. In all of these examples I use subl for SublimeText, so substitute your favorite editor there.
  5. Backup, backup, backup. Don’t edit any of these files without making a backup copy first.
  6. Since you’re here, let’s assume that you already know why you want to do this and how to use command-line mail.

How to

  1. Stop the mail and postfix services:

    $ sudo serveradmin stop mail
    $ sudo postfix stop
  2. Let’s make sure you have the spool directory (one of those folders not originally created with the original release of the OS X 10.8

    $ sudo mkdir -p /Library/Server/Mail/Data/spool
  3. Open the postfix launch daemon:

    $ sudo subl /System/Library/LaunchDaemons/org.postfix.master.plist
  4. Replace the plist contents with:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
    <plist version="1.0">
  5. Unload/reload the plist:

    $ sudo launchctl unload /System/Library/LaunchDaemons/org.postfix.master.plist
    $ sudo launchctl load /System/Library/LaunchDaemons/org.postfix.master.plist
  6. Open the

    $ sudo subl /Library/Server/Mail/Config/postfix/
  7. Find and replace all instances of /etc/postfix/ with /Library/Server/Mail/Config/postfix/

  8. Add the following lines to the bottom:

    # my edits
    relayhost = []:587
    smtp_generic_maps = hash:/Library/Server/Mail/Config/postfix/generic
    smtp_sasl_security_options = noanonymous
    smtp_use_tls = yes
  9. Find out who you are:

    $ whoami
  10. Open the aliases file:

    $ sudo subl /Library/Server/Mail/Config/postfix/aliases
  11. Find the line #root: you, uncomment it and replace “you” with the results of whoami:

    # Person who should get root's mail. Don't receive mail as root!
    root: adam 
  12. Initialize the alias database:

    $ sudo newaliases
  13. Find out your machine name:

    $ hostname
  14. Open the generic file:

    $ sudo subl /Library/Server/Mail/Config/postfix/generic
  15. Add these lines to the end (with your credentials in place of whoami and hostname):

    # my generic edits
  16. Create a password file:

    $ sudo mkdir -p /Library/Server/Mail/Config/postfix/sasl
    $ sudo subl /Library/Server/Mail/Config/postfix/sasl/passwd
  17. Add the following (with your credentials):

  18. Set postfix permissions:

    $ sudo postfix set-permissions
    $ sudo postmap /Library/Server/Mail/Config/postfix/sasl/passwd
  19. Start the mail services:

    $ sudo postfix start
    $ sudo serveradmin start mail