Getting Postfix sending email on your Mac
I have recently been setting up my MacBook (running Leopard) to send email using the local email delivery system, i.e. Postfix. This means modifying the default installation to relay email through my ISP/email service - in my case; FastMail. I use FastMail because they have a nice secure email setup with both IMAP and SMTP access encrypted using SSL, but the instructions below will also work with Google Mail. The advantage of having your Apple Mac set up like this is that it enables command line scripts and various unix programs to send email. In my case, it allows me to use Mutt and Emacs as my email client.
The first step is to modify the main.cf file in the /etc/postfix directory. Use your favourite editor to do this, but you will need to sudo in order to modify the file. If you are using vi, type 'sudo vi /etc/postfix/main.cf' in a terminal window. Then search for a commented out "relayhost =" line and add the following:
relayhost = [mail.messagingengine.com]:587 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = smtp_sasl_local_domain = yourdomain.com #smtpd_sasl_application_name = smtpd broken_sasl_auth_clients = yes smtpd_pw_server_security_options = noanonymous smtp_use_tls=yes smtp_tls_security_level=encrypt tls_random_source=dev:/dev/urandom
Now I am relaying my email through the server mail.messagingengine.com and Postfix will attempt to connect to the server on port 587. The square brackets around "mail.messagingengine.com" tell Postfix not to do an MX lookup on the name, but just got to that IP address. You will want to modify these values to suit your ISP/email service. For GMail you can use the line:
relayhost=smtp.gmail.com:587
The next step is to create the file "/etc/postfix/sasl_passwd". This file contains the information you need to use to authenticate yourself against the relaying mail server (in other words, your GMail username and password). Add the following lines to the /etc/postfix/sasl_passwd file:
[mail.messagingengine.com]:587 *username*:*password*
Or if you use GMail:
smtp.gmail.com:587 *username*@gmail.com:*password*
Remember to replace *username* with your actual username and *password* with your password.
From the Terminal command line, run the following commands:
sudo postmap hash:/etc/postfix/sasl_passwd sudo chown root:wheel /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db sudo chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
These commands create the "/etc/postfix/sasl_passwd.db" file from the "/etc/postfix/sasl_passwd" file, and then change the permissions on the file so that they can only be read by the root user.
Congratulations! You should now be good-to-go. Try sending an email from the command line by typing "mail -s 'Test Email' yourname@yourisp.com" at the command line. Type some words and then type "Ctrl-D" to finish. You can monitor the log file at /var/log/mail.log in order to see what is happening, and use the "mailq" program to see the state of the mail queue.
Related posts:

I didn’t have issues with Postfix on 10.5, but 10.6 was not letting me send emails from PHP. This did it.
Thank you so much!
After a while, I start getting these messages:
Sep 2 20:42:56 [machinename] postfix/master[10344]: warning: process /usr/libexec/postfix/pickup pid 16520 exit status 1
Sep 2 20:41:55 [machinename] postfix/master[10344]: warning: /usr/libexec/postfix/pickup: bad command startup — throttling
Any ideas? I then have to stop and start postfix and reenables deliveries, but I don\’t know what\’s going on.
I am following your instructions verbatim, but this happens after a few hours.
I’ll investigate now and see if I can work out what’s going on.
The problem you are getting seems to be related to Postfix’s pickup process. Have you changed your /etc/postfix/master.cf at all? Also, are you running postfix as a daemon? I am not – postfix starts up for me when I send mail locally and terminates after the last message is sent.
I have not touched the master.cf, the only one I have modified is the main.cf with your suggested updates and by changing the mydomain and myhostname vars within it.
The only other update I have done was the one described on this link [http://switch.richard5.net/2006/08/19/fatal-open-lock-file-pidmasterpid/] because I was getting thefollowing error: open lock file pid/master.pid unable to set exclusive lock: Resource temporarily unavailable.
As far as running postfix as a daemon… I don’t think I know how to tell whether I am or not.
Any ideas?
Interestingly, if I run launchctl on my MacBook, I see the org.postfix.master entry. I don’t have it disabled on my machine via the /System/Library/LaunchDaemons/org.postfix.master.plist file.
If you do a
ps aux | grep post, can you see any processes running that belong to the _postfix user?The other thing to check would be the permissions in your
/var/spool/postfixdirectory.The pickup process is supposed to send messages to the cleanup program for deletion. It is obviously running into problems when trying to do this, but I’m not sure why this is.
I restarted my MP and all looks good, I had to recreate the sasl_passwd files to use different smtp credentials and I think I am very close to where I want to be.
Thanks again, you provided invaluable insight.
Regards.
I didn’t have to change the permissions on the spool/postfix directory either.
Great! Glad it’s all working now.
Right now my server is always sending email as one email account, say, smtpuser@domain1.com.
If the Mac is hosting several domains, do you know how can I get to do this:
domain1.com sends email as smtpuser@domain1.com
domain2.com sends email as smtpuser@domain2.com
…
domainX.com sends email as smtpuser@domainX.com
To take into consideration: all smtpuser@ are part of their own GoogleApps account, so authentication is done via smtp.gmail.com.
All I need now is that domain1.com uses the related smtp account.
Any guidance will be greatly appreciated.
Sorry for bugging you again and for not replying earlier.