Sending email from a local development machine using a Smart Host

Sending email from your local machine using Drupal or any other PHP based application often does not work. The solution is to use a remote mail server (called Smart Host) for delivering emails.

Most ISP's mail servers today are preventing mail relaying or fighting SPAM at the SMTP level. Consequently sending email from Drupal or other PHP applications using your local Apple or Linux machine probably never hits the addressee. This makes developing mail functionality somewhat inconveniently.

The solution is to configure your local MTA (mail transport agent) like Postfix to use a remote mail server (called Smart Host) for delivering emails.

At Mac OS X 10.5 the Postfix MTA is available and can be configured using a Smart Host with SSL based SMTP authentification. To follow this steps in your Terminal.app (or Shell) you need:

  • your.isps.mailserver: The SMTP server you want to use as Smart Host
  • username and password for the SMTP server
  • The SMTP server must speak SMTP over TLS/SSL


sudo postconf -e relayhost=your.isps.mailserver smtp_use_tls=yes smtp_sasl_auth_enable=yes smtp_sasl_password_maps=hash:/etc/postfix/smtp_auth tls_random_source=dev:/dev/urandom smtp_sasl_security_options=noanonymous
sudo sh -c 'echo "your.isps.mailserver username:password" >> /etc/postfix/smtp_auth'
sudo chown root:wheel /etc/postfix/smtp_auth
sudo chmod 600 /etc/postfix/smtp_auth
sudo postmap hash:/etc/postfix/smtp_auth

Send yourself a test email from the shell: echo "test" | mail -s "test" your@email
Check /var/log/mail.log for errors regarding the delivery to the smart host.

Mouse addicted users may consider using the MailServeForLeopard Mac application instead of doing the configuration described above.

Comments

Helpful - One Tip

Thanks for the tutorial. Very helpful. One tip would be if you use a non default smtp server port then steps 1 and 4 need to be in the servername:port format. ISPs have been shutting down 25 all over the place and I needed to add 587 so my first line would be:
sudo postconf -e relayhost=your.isps.mailserver:587 smtp_use_tls=yes smtp_sasl_auth_enable=yes

Line 4 would be:

sudo sh -c 'echo "your.isps.mailserver:587 username:password" >> /etc/postfix/smtp_auth'

Hope that helps someone.
Larry

That's right, thanks for

That's right, thanks for mention it. RFC 4409 is introducing Port 587 for submission purposes of email and is used by modern SMTP software (MTAs).