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 Server.app or serveradmin CLI (now burred deep within the Server.app, 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/.
Assumptions
I assume a few things here:
- You have Server.app installed on your Mac.
- You’re comfortable in the command line.
- serveradmin have been buried recently. I suggest you add
/Applications/Server.app/Contents/ServerRoot/usr/sbinto your$PATH. - 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
sublfor SublimeText, so substitute your favorite editor there. - Backup, backup, backup. Don’t edit any of these files without making a backup copy first.
- 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
-
Stop the mail and postfix services:
$ sudo serveradmin stop mail $ sudo postfix stop
-
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 Server.app):
$ sudo mkdir -p /Library/Server/Mail/Data/spool
-
Open the postfix launch daemon:
$ sudo subl /System/Library/LaunchDaemons/org.postfix.master.plist
-
Replace the plist contents with:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>AbandonProcessGroup</key> <true/> <key>Label</key> <string>org.postfix.master</string> <key>OnDemand</key> <false/> <key>Program</key> <string>/usr/libexec/postfix/master</string> <key>ProgramArguments</key> <array> <string>master</string> </array> <key>QueueDirectories</key> <array> <string>/Library/Server/Mail/Data/spool/maildrop</string> </array> </dict> </plist> -
Unload/reload the plist:
$ sudo launchctl unload /System/Library/LaunchDaemons/org.postfix.master.plist $ sudo launchctl load /System/Library/LaunchDaemons/org.postfix.master.plist
-
Open the main.cf:
$ sudo subl /Library/Server/Mail/Config/postfix/main.cf
-
Find and replace all instances of
/etc/postfix/with/Library/Server/Mail/Config/postfix/ -
Add the following lines to the bottom:
# my main.cf edits relayhost = [smtp.gmail.com]:587 smtp_generic_maps = hash:/Library/Server/Mail/Config/postfix/generic smtp_tls_loglevel=1 smtp_tls_security_level=encrypt smtp_sasl_auth_enable=yes smtp_sasl_password_maps=hash:/Library/Server/Mail/Config/postfix/sasl/passwd smtp_sasl_security_options = noanonymous smtp_use_tls = yes
-
Find out who you are:
$ whoami
-
Open the aliases file:
$ sudo subl /Library/Server/Mail/Config/postfix/aliases
-
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
-
Initialize the alias database:
$ sudo newaliases
-
Find out your machine name:
$ hostname
-
Open the generic file:
$ sudo subl /Library/Server/Mail/Config/postfix/generic
-
Add these lines to the end (with your credentials in place of whoami and hostname):
# my generic edits whoami@hostname [email protected] @hostname [email protected]
-
Create a password file:
$ sudo mkdir -p /Library/Server/Mail/Config/postfix/sasl $ sudo subl /Library/Server/Mail/Config/postfix/sasl/passwd
-
Add the following (with your credentials):
[smtp.gmail.com]:587 [email protected]:yourpassword
-
Set postfix permissions:
$ sudo postfix set-permissions $ sudo postmap /Library/Server/Mail/Config/postfix/sasl/passwd
-
Start the mail services:
$ sudo postfix start $ sudo serveradmin start mail

