How can I print e-mail messages sent by Drupal to the screen for debugging purposes? For debugging, I'd like to print the values being used to send e-mail messages to the screen.

After enabling the devel module, I tried this code (modified as per Letharion's comment):

function MY_MODULE_mail_alter(&amp;$message) {
  dpm($message, 'email_test');
}


I don't get any error message, but I don't see any output, either.  How can I print the value of '$message' to the screen?

More details about my site:

I'm trying to debug the e-mails sent upon user registration.  There should be one sent by Drupal itself via the Logintoboggan module and another sent by the Rules module.

Anonymous users have the same permissions as admin to view debug messages; I tested this by adding a dpm() in my page.tpl.php.

I tried setting Display redirection page to on as per Clive's comment but the workflow is unchanged from before.  If I add debug($message) to the MY_MODULE_mail_alter() then debug() will print the message from Drupal/logintoboggan but not the message from Rules.
The way I debug email is by using the TestingMailSystem class:

// Use testing mail system.
variable_set('mail_system', array('default-system' =&gt; 'TestingMailSystem'));


You can then capture and print the mail contents with the following statement:

$mails = $this-&gt;drupalGetMails();
debug($mails); // $mails is an array holding all mails sent.


Here $this is the current testing class (instance of DrupalWebTestCase).

This is very simple to use as part of automated testing (using the Testing framework that is part of the Drupal core).

If you don't want to be troubled by setting up the full Testing framework, an alternative method for debugging email is to hijack drupal_mail.

To do this you need to install the Devel module and
edit the core mail.inc by replacing the standard drupal_mail with the following function:

/**
 * Function to debug mail.
 */
 function drupal_mail($module, $key, $to, $language, $params = array(), $from = NULL, $send = TRUE) {
  dpm('Using hacked version of drupal_mail.');
  dpm($params, 'mailbody');
  // Print out more arguments if required.
  return TRUE;
}


And yes, this is hacking core, so:  1) Don't do this on a production site; and 2) Remember to restore mail.inc with a pristine version when done debugging.

Note: The latter method is a rather nasty hack (but I've found it useful a few times).  Using the Testing framework to debug mail is the recommended method.