Chad WoolleyChad Woolley
Enabling the Postfix Mail Daemon on Leopard
edit Posted by Chad Woolley on Monday September 08, 2008 at 08:29PM

If you want to send SMTP mail via localhost on Mac OSX Leopard (for example, from ActiveRecord/Rails/CruiseControl.rb/etc), you need to run postfix at boot. This took me a quite a while to figure out, so here is what worked for me on a work-imaged box and my personal box. YMMV.

  • First, Leopard comes with postfix, but I had numerous issues because I had the MacPorts version already installed on all my boxes for whatever reason. Here are the various error search strings for future googlers:
    • fatal: file /opt/local/etc/postfix/main.cf: parameter mail_owner: user postfix has same user ID as _postfix
    • fatal: open /usr/local/etc/postfix/main.cf: No such file or directory
    • fatal: open /opt/local/etc/postfix/main.cf: No such file or directory
  • So, I ended up uninstalling the MacPorts version:
    $ sudo port uninstall postfix
    
    • Strangely, after this, I still get a version @2.5.4 returned by "sudo port list postfix", even though the uninstall was apparently successful. I don't know enough about MacPorts to know why, maybe this is reporting the Leopard-installed one???
  • Next, I edited the plist file to start postfix automatically on boot:
    $ sudo vi /System/Library/LaunchDaemons/org.postfix.master.plist`
    
    • Add these entries at the bottom, in the 'dict' element
       
      <key>RunAtLoad</key>
      <true>
      <key>OnDemand</key>
      </true><false>
      </false>
  • Reboot
  • Make sure SMTP port 25 is open on localhost
    • $ telnet localhost 25
    • Look for something like the following, showing you connected successfully on localhost:
      Trying ::1...
      telnet: connect to address ::1: Connection refused
      Trying fe80::1...
      telnet: connect to address fe80::1: Connection refused
      Trying 127.0.0.1...
      Connected to localhost.
      Escape character is '^]'.
      220 citestbox.localhost ESMTP Postfix
      
    • Hit Ctrl-] to get to the telnet> prompt
    • Type quit to exit

And that was it! CruiseControl.rb was now sending email from OSX, which was all I really wanted in the first place...

Comments

  1. Karl Karl on September 09, 2008 at 08:43PM

    I gave up on postfix on OS X a while ago. Maybe I'll give it a try again, just when I became accustomed to using smtp for development and sendmail for production.

  2. David James David James on September 25, 2008 at 08:36PM

    Readers may also be interested in this posting titled "10.4 Enable postfix without inducing insomnia" -- intended for Tiger, not Leopard -- but maybe it will be of use: http://www.macosxhints.com/article.php?story=20050504131428334

    Personally, I don't need the postfix daemon to listen on port 25. I'm having enough trouble just sending email via sendmail. I'm getting this error: "postdrop: warning: unable to look up public/pickup: No such file or directory". Any suggestions?

    I'm not great at Postfix; any tips on how to do some basic testing would be great -- i.e. simple command line tests to see if things are working right.

  3. Chad Woolley Chad Woolley on September 28, 2008 at 05:40AM

    @David,

    heh i'm no expert either. As for sendmail, why do you need it? Can't you use postfix instead?

    As for confirming postfix is working, the telnet-to-port-25 approach I mentioned in the post should work. If it is up and accepting connections, then it should "just work" to send mail.

    -- Chad

  4. Flemming Funch Flemming Funch on November 21, 2008 at 01:06PM

    For others who get stuck at that point, what worked for me to add at the bottom of the dict element is:

    RunAtLoad OnDemand

    Looks like your xml got tidied up so it no longer worked.

    Thanks for the explanation, now it works for me.

  5. Flemming Funch Flemming Funch on November 21, 2008 at 01:10PM

    Oops, no, that's not what I put in. The comment editor mangled that too. I'm trying one more time, and if it still doesn't work, just know that it needs to be fixed. The second key is not a sub-element of the first key.

    <key>RunAtLoad</key> <true/> <key>OnDemand</key> <false/>

  6. Adam Adam on December 30, 2008 at 06:08PM

    I still unable to get this working.

    My telnet localhost 25 returns, so only checking the 127 address: Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 firefly.local ESMTP Postfix

    I've reloaded, restarted postfix then tested using:

    mail myaddress@domain.com subject : test body . EOT

    No email.

    I even pasted in the main.cf content from a colleague who is able to send email from the command line and it still fails.

    Any ideas?

    Small correction, the port list command you used provides the available ports not the installed ones. You are correct, you don't have the postfix port installed =)

    Link: http://guide.macports.org/

    Relevant sections: The installed option displays all installed ports.

    The list option is used to get a list of all available ports. The list of available ports is very long, so use search if you know a port's name or part of it.

  7. Chad Woolley Chad Woolley on December 30, 2008 at 09:59PM

    @adam,

    Hmm. Kind of suspicious that localhost doesn't resolve for you. Do you mean you can't ping localhost? I'd fix that first (put it in your hosts file), maybe it is related to your problem (some relevant config file is referring to localhost)...

  8. Adam Adam on December 30, 2008 at 10:20PM

    @chad

    Thanks for the quick reply. I was/am able to ping localhost and the telnet localhost 25 command returned sucess as you suggested, though it did not show the 2 initial Connection refused errors your listed.

    <code>
    telnet localhost 25
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    220 firefly.local ESMTP Postfix
    
    
    ping localhost
    PING localhost (127.0.0.1): 56 data bytes
    64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.041 ms
    64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.086 ms
    64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.066 ms
    64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.083 ms
    </code>
    

    I noticing that the mail was failing with a timeout when inspecting "mailq". I then added authentication as per Matt Sears post and it's all working now.

    I've posted a few commands and links here

  9. huned huned on February 02, 2009 at 08:47PM

    Note that instead of rebooting, you can just use launchd to start postfix:

    $ sudo launchctl $ start org.postfix.start

    After you quit launchctl, telnet to localhost:25 will work.

  10. George Anderson George Anderson on March 09, 2009 at 03:04AM

    @huned: nice, I didn't want to reboot.

    One small typo though:

    $ sudo launchctl

    $ start org.postfix.master (not start as above)

    Thx again.

    /g

  11. Jim Jim on April 13, 2009 at 03:57AM

    Some updates to an aging, but useful post:

    Matt Sears' gmail/postfix relay post URL changed, as did the URL Adam's useful postfix commands blog post

    As noted above sudo launchctl start org.postfix.master will start it, sudo launchctl stop org.postfix.master will stop it, as will sudo postfix start and sudo postfix stop

    And you'll likely want to edit /etc/postfix/main.cf before you do any of this.

  12. Brian Armstrong Brian Armstrong on May 16, 2009 at 02:32AM

    Note that to see if it's work you can use this: ps aux | grep postfix

    I was originally using this: ps -ef | grep postfix

    But it came up with nothing because postfix was running as it's own user. After several reboots I thought it wasn't working but it was.

    For anyone still having trouble, try Adam's post which has more details: http://blog.redcoded.com/post/67554541/command-line-emails-with-postfix-on-leopard-10-5-5

    Good luck! Brian

  13. cmholm cmholm on October 14, 2009 at 06:09PM

    Unfortunately, as of Oct 2009, Adam's blog doesn't seem to be hosted at redcoded.com, anymore.

    Once the org.postfix.master.plist changes are in (which I'm not sure I needed, in my case), the final step towards getting rid of the "fatal: ... as _postfix" error in the mail log is to edit /etc/postfix/main.cf so that:

    1) mail_owner = _postfix 2) setgid_group = _postdrop