Lion, SMTP Postfix Relay, and Dreamhost

When developing web-apps locally it is useful to have a fully functional smtp server to test automated emails associated with your application. Many times the network you are developing on will not allow you to simply start up postfix and and run your own local smtp server. However, this doesn’t imply that you can’t use postfix – modifying postfix to relay all outgoing mail to an external / offsite smtp server that you have control of will enable you to develop & test the parts of your application that require a local outgoing smtp server without an issue.

Many times port 25 (the default smtp port) will be blocked somewhere along the line in your network connection. You can figure out if your network configuration or ISP is blocking port 25 by running

telnet smtp.server.com 25.

Edit /etc/postfix/main.cf

relayhost = [mail.domain.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_use_tls = yes

Create/edit /etc/postfix/sasl_passwd

[mail.domain.com]:587 username@domain.com:password

Run this command in your shell once the above two files are created/modified:

sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
sudo launchctl stop org.postfix.master
sudo launchctl start org.postfix.master

# test postfix, cmd+d after typing message content to send message
mail -s "Testing, Testing" you@domain.com

References:

9 Responses to “Lion, SMTP Postfix Relay, and Dreamhost”


  • To save the next person reading this a minute, I don’t have “/etc/postfix/sasl_passwd” but I do have a “/etc/postfix/sasl/passwd”. Probably a typo.

  • Matt, are you running lion? I don’t have /etc/postfix/sasl/passwd on my installation. To clarify, you have to create the /etc/postfix/sasl_passwd file.

  • Hi,
    I was trying to enable the above, but after entering “sudo postmap /etc/postfix/sasl_passwd” I got:
    postmap: fatal: open database /etc/postfix/sasl_passwd.db: Permission denied
    Any idea what could be causing that?
    Kind regards
    Tim

  • Hi,
    Discovered that my BBedit that I invoked to create sasl_passwd wasn’t creating a root owned file. Invoked Vim to create it, and succeeded in creating a root-owned file, and thus the postmap exercise was allowed to create the sasl_passwd.db file.
    Just thought I’d let you know I’d overcome my problem.
    Tim

  • Thanks a bunch… you saved me.

  • No doubt this works, however there is something else going on here with Lion, other than port 25.
    My local MAMP set-up was fine sending mail() with PHP until the moment I upgrade to Lion.

    I do not believe my ISP decided to block port 25 the same day I upgrade ;-) so leads me to think there is something else.

  • Thanks man, it worked to me.

  • Is port 587 selected at random? I read the link on port 25 blocking and it indicated that 587 was linked to Dreamhost… which looks like a hosting provider.

    Is this just a way of mapping port 25 through Dreamhost via port 587? (A service provided by Dreamhost??)

    Regards use of port 25:
    My hosting provider uses port 26 for mail server access for my POP account. Presumably, there’s a way to set this in postfix somewhere. I tried using port 26 in place of 587, but it didn’t work. I’m not even sure it SHOULD have worked. (Sorry, if the questions seem uninformed. It’s because they ARE! This is the first time I’ve tried to do anything with postfix.)

    To end a message, is it cmd-d or ctl-d?

  • Did some more research on other websites and realized my mistake(s). Mistakenly thought that the “mail.domain.com” references were queues to enter my OWN domain name (just as username@domain.com:password is not a cue to enter “username@domain.com:password” as a literal) and that the brackets were a cue to substitute an actual domain.

    To others that have fallen into the same trap, the ONLY thing you need to change from the information listed above is “username@domain.com:password”. The brackets and generic domain, as in “[mail.domain.com]” are literal and should not be changed.

    Also, of course, in the test message, use a real address instead of “you@domain.com”. And use ctrl-D to end the message.

Leave a Reply