9th June 2015

Drupal Maillog Module

John Ennew
Technical Director

The Drupal Maillog module solves two issues:

  1. Being able to review all emails being sent from a site
  2. Stopping emails from being sent from a site

The module intercepts all email due to be sent from a Drupal website. Once it has done this, it can be configured to both log the emails so they can be reviewed and still send the emails on.

We enable the Maillog module in all environments (production and the development and stage environments) and then use settings.php to put the configuration for each environment in code.

Below is an example configuration settings for a production environment which needs the emails to be logged and then sent out:-

// Maillog settings.
$conf['mail_system'] = array(
  'default-system' => 'MaillogMailSystem',
  'maillog' => 'MaillogMailSystem',
);
$conf['maillog_send'] = TRUE; // Do send the email.
$conf['maillog_log'] = TRUE; // Do log the emails.
$conf['maillog_engine'] = 'DefaultMailSystem'; // Use this as the email engine.

The mail_system conf setting is a core Drupal configuration which tells Drupal which email handlers exist and which should be used as the default handler. Here we can see that MaillogMailSystem is set to be the default and so will be the one which is used to handle all emails from the site. 

The maillog_engine conf setting is a maillog module setting which tells maillog which email handler to pass the email onto if maillog_send is set to TRUE.

Here is an example configuration for a development environment where we want to log the emails being sent but do not want to actually send the emails.

// Maillog settings.
$conf['mail_system'] = array(
  'default-system' => 'MaillogMailSystem',
  'maillog' => 'MaillogMailSystem',
);
$conf['maillog_send'] = FALSE; // Do not send the email.
$conf['maillog_log'] = TRUE; // Do log the emails.

Next is an example production environment configuration for a site which uses the Mandrill module to have the Mandrill service send emails instead of the Drupal default. Since we do not want to log emails on this site the Maillog module is redundant but we still want it enabled because it will still be useful in the development environments. By enabling the module in production then it will still be enabled when we drag the database down from production to development where it needs to be enabled.

// Maillog settings.
$conf['mail_system'] = array(
  'default-system' => 'MandrillMailSystem',
  'maillog' => 'MaillogMailSystem',
  'mandrill' => 'MandrillMailSystem',
);

If you have the Drupal Views module enabled and have configured Maillog to log emails then a Maillog section will appear under admin/reports on the site. This lists all the emails the site has sent or would have sent if maillog_send is set to FALSE. Note that this report will only appear after you have cleared cache so is not immediatley available after enabling the module.

The Maillog module is a useful tool for managing and reviewing emails on a Drupal site. By enabling the module in all environments it is always there even if we pulled the database down from production to development. By placing configuration in code we can be precise about the way Maillog behaves in each environment.

Maillog can also help to give assurance that emails will not be sent to real people in the development environments. However, we also suggest using the reroute email module to give additional protection.