While debugging, testing 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 platforms (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 suggests, 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.
Installing and configuring the SMTP Authentication Support module is an easy way to allow Drupal to bypass the PHP mail() function and send email directly to an SMTP server. The module supports SMTP authentication and can even connect to servers using SSL if supported by PHP.
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.
Aliasing Your Existing Mail Account
When multiple email accounts are needed, many mail providers, such as Gmail, allow for email aliasing. This allows for multiple Drupal accounts to be sent to a single mail account.
This can also be used to redirect multiple real user email address to another account. This is useful if you have a dev or test environment that is a dump of your live environment with real user data. This SQL statement will update all your email addresses, so that no actual emails go out to your live users.
SET mail = CONCAT('youremail+',CONCAT(REPLACE(mail, '@', '.AT.'),'@gmail.com'))
Change "youremail" to the first part of the email address you plan to use. For example, if you want to send email to email@example.com, change youremail to john.
This is known to work for Google Apps Mail (which is Gmail) as well. In that case, you should change "gmail.com" to your own domain. If you receive email at firstname.lastname@example.org, then your domain is
If you use Drush, you can use the --sanitize option to sql-sync when you clone your development database from Staging or Production. This will obfuscate users' e-mail addresses, but there's also an option to set them all to something specific: --sanitize-email.
If you have already have a database you'd like to update, then you can run the following from your site directory.
drush sqlq "UPDATE users SET mail = CONCAT('youremail+', CONCAT(REPLACE(mail, '@', '.AT.'), '@gmail.com'))"
Make sure that you do this on the right database! You can check the database Drush will use by running
Shared Email Module
The shared email module overrides the 'user' module's validation that prevents the same email address being used by more than one user. Works for both registration and account updates. Displays a warning to the user that they are using a shared email.
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.
Mail to Database Log (Drupal 6)
The Drupal 6 version of the Devel module ships with an smtp_library implementation which logs emails to the Watchdog.
Once the Devel module is installed, go to Administer -> Site configuration -> Devel settings. On that page there is a section titled SMTP library. Select 'Log only'. After sending an email from your site, go to Administer -> Reports -> Recent log entries. Among the log you should now see any outgoing messages. By clicking on the text under the 'Message' column you can see more details about that specific message.
Mail to Database Log (Drupal 7)
The Helper module has a mail handler that writes all emails to the database log. After sending an email from your site, go to Administer -> Reports -> Recent log entries, and you can view the email's details. To switch your site's mail handler to Helper's, add the following inside settings.php:
$conf['mail_system'] = array('default-system' => 'HelperDebugMailLog');
Mail to Temp Files
The watchdog logging functionality was removed in the Drupal 7 version of the Devel module, in favor of logging to temporary files instead. To enable temp file logging, add the following to your site's settings.php file:
$conf['mail_system'] = array(
'default-system' => 'DevelMailLog',
Each individual outgoing message will then be written to its own file in the temporary directory designated for the site (typically /tmp). More information can be found in the documentation for DevelMailLog.
Fakemail is a perl script that just works out of the box as long as you have perl installed. You just run the script, it listens on port 25, and dumps all mail received into a directory. You have no risk of spurious email being delivered to users by means of your sandbox.
Mail Transfer Agents
If you wish to have a more complete solution, you can use a mail transfer agent like Postfix, Exim or Sendmail.
Postfix is a well-known and widely used free-and-open-source mail transfer agent.
To use Postfix, it must be installed on your server, or a server you have command-line access to. Installation and configuration of Postfix is beyond the scope of this page, however there is documentation available. Postfix runs on Linux, OSX, Unix or under Windows using Cygwin.
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 an open relay
mydestination = $myhostname, localhost
You can find more complete documentation on how to configure Postfix on the Basic Postfix Configuration page.
To read emails using a command line reader such as the mail command, pine, elm, or mutt, a user account must be created on your server. In this example, the user would be "mailtest."
Then, to use this account, send mails to mailtest@ and read it using the command line reader.
Postfix can also relay messages to any mail account, such as Gmail, Yahoo, Hotmail.
Exim is another well-known free and open source mail transfer agent. It runs on Linux or under Windows using Cygwin. Create a user account and read the mail using the mail command, pine, elm, mutt or other mail reader as described above. Exim can also relay messages to any mail account such as Gmail, Yahoo, Hotmail, etc.
sSMTP is a simple MTA to deliver mail from a computer to a mail hub (SMTP server) like e.g. gmail. sSMTP is simple and lightweight, there are no daemons or anything hogging up CPU.
To install ssmtp:
sudo apt-get install ssmtp
sudo nano /etc/ssmtp/ssmtp.conf
Possible configuration using gmail:
Configure php: In php. ini change:
sendmail_path = /usr/sbin/ssmtp -t
On OSX, MailServe provides another option, although it is not free or open source.
Free SMTP Server
Third Party Solutions
mailtrap.io - This is a free (for the present time at least, I don't know if they plan to have people start paying later) service that allows you to configure postfix/phpmailer/whatever you use to send mail to mailtrap.io instead. Mailtrap will buts it in it's inbox on their servers. Allows forwarding to personal e-mail addresses as well as giving "inbox" access to other mailtrap.io users so that multiple people can view the same mailbox.