Setup postfix to relay local mail in OS X Mountain Lion

I generally get by without needing to send email from any of my local development web applications. Of course, that was until today. I have an issue to dubug in the Guardr Drupal distribution and am getting some sendmail errors when running drush qd.

A bit of research resulted in getting postfix up and running as a sendmail service in OS X Mountain Lion (10.8.2). Here are the steps which worked for me:

  • Execute the following to setup the mail spool and proper postfix permissions. I found this on stackexchange when initially researching why I was getting errors stating /Library/Server/Mail/Data/spool did not exist. Update: If you do not get this error, you may not need to use the next few commands. You may be able to just skip to the section on starting postfix. Some of these related issues may be resolved in newer versions of OS X Mountain Lion.

$ sudo mkdir -p /Library/Server/Mail/Data/spool

$ sudo gzip /usr/share/man/man1/{postalias.1, postcat.1, postconf.1, postdrop.1, postfix.1, postkick.1, postlock.1, postlog.1, postmap.1, postmulti.1, postqueue.1, postsuper.1, sendmail.1}

$ sudo gzip /usr/share/man/man5/{access.5, aliases.5, bounce.5, canonical.5, cidr_table.5, generic.5, header_checks.5, ldap_table.5, master.5, mysql_table.5, nisplus_table.5, pcre_table.5, pgsql_table.5, postconf.5, postfix-wrapper.5, regexp_table.5, relocated.5, tcp_table.5, transport.5, virtual.5}

$ sudo gzip /usr/share/man/man8/{anvil.8, bounce.8, cleanup.8, discard.8, error.8, flush.8, local.8, master.8, oqmgr.8, pickup.8, pipe.8, proxymap.8, qmgr.8, qmqpd.8, scache.8, showq.8, smtp.8, smtpd.8, spawn.8, tlsmgr.8, trivial-rewrite.8, verify.8, virtual.8}

$ sudo /usr/sbin/postfix set-permissions

$ sudo chmod 700 /Library/Server/Mail/Data/mta

  • Follow the stops on this blog post by Benjamin Rojas‚Äôs
    • When I tried to send a test email after starting Postfix with sudo postfix start, I noticed I was receiving this error in the /var/log/mail.log: Fatal: open lock file pid/master.pid. Postfix was already running according to OS X becuase it loaded at startup via a system LaunchDaemon. This blog post tipped me off, but I found a different fix to the issue. To resolve, I ran the following command to remove the running Postfix instance by executing the follwing in terminal: sudo launchctl unload /System/Library/LaunchDaemons/org.postfix.master.plist
  • Start Postfix: sudo postfix start
  • Test email: date | mail -s test youremailaddress@yourdomain.com
  • If the test email worked, great! Now, reboot your Mac and Postfix should start up automatically since the Apple already starts it via a launchdaemon.

My next step is to add the above procedure to BrewStack!

Update: See this update for OS X Mavericks

Blog Category: