Sunday, September 19, 2010

POSTFIX is not an email client

Why in the world would one want to use Postfix or Sendmail for simply sending an email from a program on OS X?

I wanted to write a shell script to send an email to blogger, to make it trivial to blog stray thoughts and questions while programming. Simple right? But one of the most common responses is to suggest setting up Postfix.

That's just plain dumb. On SnowLeopard, as in other UNIXes, shell scripts and other programs usually rely upon a mail daemon to do the work of managing emails.  But why use a 500 pound gorilla to do the work of a 5 ounce lemur ?

Postfix is a clone of sendmail, which is one of the worst practical jokes committed by graduate students upon the rest of computing humanity. Whereas it is trivial to set up, for instance, a Thunderbird account to send email, using Postfix makes the process unnecessarily complicated. The fact that I want to send email from a shell script is not relevant: installing Postfix is neither necessary nor sufficent.  Given the amount of contextual information that needs to be discovered and mapped to configuration settings, one quickly realizes that choosing to use a solution like Postfix imposes external dependencies that can drown you in gratuitous details.

It turns out that Postfix is not configured to run on OS X.  So here's what you do to get it up and running:

Edit the daemon config and tell it to start on load:
$ sudo vi /System/Library/LaunchDaemons/org.postfix.master.plist`


Then change your /etc/postfix/ to relay through your ISP's mail server:
sudo vi /etc/postfix/
mydomain =
myorigin = $mydomain
relayhost =

Now reboot or start postfix manually:
$ sudo postfix stop
$ sudo postfix start

Even after setting it up, my mail still wasn't getting out. The mail log said the messages were being sent, but they were not getting delivered. A little later, a message showed up in my local account inbox. By the by, the shell reminds me of this little fact -- I would not know had I not been using a command line shell. But I don't actually _want_ to have local mail enabled at the UNIX level. Doing so presents many more opportunities for abuse, and hassles with keeping another daemon going when other software is updated. 

The problem seems to be that the RoadRunner SMTP server requires a valid username and password to be used when sending mail. So I hacked the file to specify that "" is my machine name, and rely upon the accidental fact that my username is the same as my email account name. I don't even know if it is possible to manage Postfix accounts separately and distinctly from the local UNIX system accounts.

In general, Postfix makes a very crappy email client: it is WAY too much software for simply sending mail and doesn't provide a simple and secure means of specifying email names and passwords for senders, independent of their local user account. I don't need a full blown, general purpose email server. I just need to connect to my SMTP host to send a mail.

Anyway, it is working for the moment, but choosing to try Postfix cost me valuable time.  A better alternative would have been a scripting language like Python or Ruby, but I like not having shell scripts without dependencies on other scripting languages... and sometimes even the libraries rely upon postfix or sendmail for sending email. Another option is to use another utility to connect directly to the SMTP port, and force feed an SMTP message directly through the system. That approach would be low level, but that would have fewer external dependencies.

No comments: