Setting up a mail server for development

While debugging or coding new features, if you want to see the content of the mails sent by your test Drupal site, your development platform should be properly set up so that mails are sent to a place where you will be able to find them.

Most of the notes that follow should be applicable to all platform (Linux, Mac, Microsoft).

Drupal specific mail backend

Drupal can use an arbitrary mail backend. Look into http://api.drupal.org/api/function/drupal_mail_send/6 (in Drupal 6) or http://api.drupal.org/api/function/drupal_mail/5 (in Drupal 5). You can set the smtp_library variable to a file name, which Drupal will include and "send mail" with a drupal_mail_wrapper() function defined in that file. There you can log the mail to the database, a file or whatever. So all mail going out from Drupal can be nicely debugged locally. If you really need to send the mail over some server, as the name of the variable suggest, you can use an SMTP library and use any SMTP server you use otherwise to send mail, though I didn't have problems I solved this way though.

Reroute Email

A related module is reroute email. It intercepts all outgoing emails and reroutes them to an address you specify. This is very useful in development when you have a copy of a live site with thousands of users, and modules that send email (e.g. subscriptions), so email does not go to real users from the copy site. You can also add debug info in the email if you wish via a theme function.

PHP CLI script

This is covered nicely by chx at http://www.drupal4hu.com/node/55 . In short: you set PHP to send mails to a file.

In some distributions of Linux, you have to make sure to install the package php-cli.

Mails to logs

devel.module ships with an smtp_library implementation which logs emails to the watchdog. You can review the contents using the usual Drupal web admin.

Postfix

If you wish to have a more complete solution, you can install a mail server like postfix.

Install the package postfix. Here is the minimum configuration you will need: in /etc/postfix/main.cf configure

myhostname = <the hostname of your box> #if it is simply 'localhost', you can leave this line commented out.
inet_interfaces = localhost # so that it won't be open to the world
mydestination = $myhostname, localhost

Create a user mailtest on your box
send mails to mailtest@ and read it via mail command or install pine or elm.

 
 

Drupal is a registered trademark of Dries Buytaert.