This hint provides an alternative mechanism to create an SMTP daemon that listens and accepts connections on port 25 (the standard SMTP port) that is (more) appropriate for desktop/laptop users, without disturbing much of the out-of-the-box 10.4 setup and behavior.
Motivation
I suffer from mild obsessive-compulsive disorder when it comes to system administration, especially on my own machines. While I appreciate the simplicity of tools like Postfix Enabler, I naturally distrust their ability to do The Right Thing™, especially since tools like these typically hide the details of what they change "under the covers."
There are already a few hints (e.g., here and here) which explicitly advise how to set up postfix in such a way that it will provide a SMTP daemon that listens and accepts connections on port 25. Many of these use launchd, but (IMHO) do so in a way that doesn't quite seem to be in complete harmony with either postfix or launchd (at least how they were intended to be used on a desktop machine).
I wanted to create a solution that modified the 10.4 "stock" postfix behavior and configuration as little as possible, without suffering from some of the problems identified in other hints (e.g., aggravating the ability of a notebook to honor its sleep settings). I thought having the postfix master process exit after 60 seconds was a good idea and wanted to preserve that behavior. I also wanted to use launchd (as I believe it was intended) to be able to launch services on an as-needed basis (rather than force them to run all the time).
Overview
We will implement a solution which will use the (mostly) default configuration of the postfix master program to handle mail as it was intended: by monitoring /var/spool/postfix/maildrop (and that's all) for new mail and handle sending it. In addition, we will use launchd to run an inetd-like daemon, on an as-needed basis, to listen for connections on port 25 and put new mail in /var/spool/postfix/maildrop.
Implementation
From a fresh installation, there are three files which must be edited/created to implement this solution. They are as follows:
MAILSERVER=-YES-
This tells OS X to automatically turn on various aspects of handling of sent mail. Ideally, this would be all we needed, but the default configuration is to only handle mail being sent via files created in the /var/spool/postfix/maildrop directory (e.g., the via the mail and sendmail Unix commands). The good news is that this is the exact behavior of which we intend to take advantage in order to disturb the default settings as little as possible.
#smtp inet n - n - - smtpd
This tells postfix that when it runs master, it should not listen on port 25 when it's running.
$ telnet localhost 25
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host
$ echo hello | mail your_email_address
$ telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 matt.local ESMTP Postfix
quit
221 Bye
Connection closed by foreign host.
Now wait 60 seconds or more before typing the next command:
$ telnet localhost 25
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host
I believe this behavior doesn't make very much sense and is not what is intended (i.e., that it is an oversight by Apple). After commenting the above line out and waiting 60 or more seconds for any existing master processes to exit, you should not be able to connect to your local port 25 regardless if any new master processes run or not.
$ sudo cat >/System/Library/LaunchDaemons/smtp.plist
Now copy the source from the window that the above link will open, and paste it into the Terminal. Then hit COntrol-D to close the file and write it.
$ sudo launchctl load /System/Library/LaunchDaemons/smtp.plist
$ sudo launchctl start org.postfix.sendmail
Now, every time you attempt to connect to port 25, launchd will spawn a new sendmail process which, when completed, will put new mail into /var/spool/postfix/maildrop which will trigger the default configuration of postfix to sweep it up and take care of it as needed.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20050911184730802