Drupal tip: Test mail sending with Devel

If you don’t want to send lots of mail to your users when you’re testing your site, change the Devel module’s SMTP Library setting to “Log Only”. Then you can check your log to see all the mail that would’ve been sent. Handy!

To enable this only on your testing server, add the following to that domain’s settings.php:

$conf['smtp_library'] = drupal_get_filename('module', 'devel');
  • Or you can use the reroute email module. This way you get all the emails by rerouted to an address you specify.


  • Chris Cohen

    Sacha, can you not just choose the SMTP library from the devel settings screen, rather than using settings.php, then turn it off on the live machine?

  • We frequently refresh our testing database with a backup from the production server, so any configuration changes would get lost.

    I already have some custom code that enables development modules. I could add an update or replace statement there.

    On the other hand, overriding it in the settings.php allows me to use normal mail delivery in my local testing environment, log-only mail delivery in the server testing environment, and normal mail delivery on the server.

    Khalid: That might be interesting. =) I’d have to set up an account that other testers have access to, though. This one works for now! =)

  • Hi Sacha, I really like your blog specially the Drupal Category. It’s great to hear Khalid in this post. I’ve been following your blog, in fact I copied the idea of your slogan.

    Thank you for posting this, its a great help, I am now doing a test in my social site.

  • Alex

    Some update – there is no need to modify settings.php as Devel has support for this.
    just navigate to Site configuration ->Devel and set SMTP library to ‘Log only”.

    • That’s a convenient way of setting it in the database, yes. I find it useful to set it using PHP in my settings.php as well as in my base test case class, though. That’s because I typically work with other developers using an integration server. At some point in the development, we switch the integration server settings to send real mail. I still want to use debug mail on my system, and I want test cases to be able to analyze mail logs wherever they’re run. :)