Module goal

When developing Drupal sites, we are often working in a development environment in which we want behaviors different than we would like on a production environment. An example of this is sending emails - it's often preferable to not send emails from a development environment, as they can end up in our client's email boxes. This is particularly true when there is a production (live) version of the site on the web, as users may receive emails from your development environment, which will be both confusing, and any links to the site within the emails will be unusable by anyone without access to that development environment.

This module aims to provide various settings which are specific to development environments only.

Current functionality

Currently, the module provides the following functionality:

  • Mail Logging - no emails will be sent from the system, and instead will be logged to the Drupal log (watchdog). Whenever a mail is attempted to be sent from the system, users will receive a message informing them that the mail was not sent, and users with 'Access development environment mail logs' permission will also receive a link to the log. The regular message stating that a mail was sent is suppressed (note - this message is currently only suppressed in English).

    This feature needs to be enabled on the settings page at admin/config/development/development_environment. Note that this setting can also be made by setting the value of $settings['development_environment.log_emails'] to TRUE (log emails) or FALSE (send emails). When this is set in settings.php will prevent toggling the sending of emails on and off through the admin UI.

Multi-environment usage

When using Drupal in a multi-environment setting (dev, staging, production), the database is often pulled from production to staging/dev, in order to test code against the current database. The problem here is that if this module is not enabled on production, then when the database is pulled from production, the module will not be enabled on whatever environment the database has been pulled to. Therefore, if a developer forgets to enable the module after pulling the database, emails may be sent out.

Here is how the module should be sent up, to ensure emails are suppressed on all environments other than production:

  1. Ensure the module exists is on all environments.
  2. Add the following to settings.php in the production environment:
    • D7: $conf['development_environment.log_emails'] = FALSE;
    • D8: $settings['development_environment.log_emails'] = FALSE;
  3. Add the following to any environments you do not want emails to be sent from:
    • D7: $conf['development_environment.log_emails'] = TRUE;
    • D8: $settings['development_environment.log_emails'] = TRUE;
  4. Enable the module on all environments

Now, because the module is enabled on production, it will be enabled on all other environments when the production DB is pulled to them. And because emails have been set to be suppressed in settings.php, they will be suppressed on these environments.

Roadmap

I am interested in adding further functionality to this module that would be beneficial for development environments, including tying in with other contributed modules. If anyone has any suggestions for developing this functionality further, or would like to contribute to this module, please post in the issue queue so we can make this module a complete module to be used in any Drupal development environments.

Supporting organizations: 
Provided initial development

Project information

Releases