How can I print e-mail messages sent by Drupal to the screen for debugging purposes?
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.