Maillog / Mail Developer (obsolete)
A development utility module that logs all emails sent through the site and optionally suppresses email delivery for debugging purposes.
maillog
Install
composer require 'drupal/maillog:8.x-1.1'
Overview
The Maillog module provides a comprehensive solution for capturing and archiving all emails sent through a Drupal site. It is primarily designed for development and staging environments where you need to inspect outgoing emails without actually sending them.
The module intercepts all mail operations through Drupal's mail system and can store complete email details in the database including headers, subject, body, recipients, and sender information. It features a Views-based interface for browsing logged emails with detailed view capabilities for each message.
Maillog is particularly useful during development when you want to prevent accidental email delivery to real users while still being able to verify that emails are being generated correctly by the system.
Features
- Logs all outgoing emails to a database table with complete details including headers, subject, body, from/to addresses, and timestamps
- Optionally suppresses email delivery to prevent emails from being sent (ideal for development/staging environments)
- Provides a Views-based overview page at /admin/reports/maillog for browsing all logged emails
- Detailed view of individual emails showing all headers and full message body
- Verbose mode displays email contents on-page when messages are sent (for users with permission)
- Option to trim email body to 512 characters to prevent database bloat
- Option to remove base64 encoded content from email bodies before logging
- Automatic cleanup via cron with configurable retention by number of logs or time period
- Drush integration with maillog:clear command to purge the log table
- Integration with MailSystem module for advanced mail routing configuration
- Notification options to inform visitors when emails are logged or delivery is disabled
Use Cases
Local Development Email Testing
Configure Maillog on your local development environment to capture all emails without sending them. Set 'send' to FALSE and 'log' to TRUE to prevent emails from reaching real users while still being able to verify email content and formatting.
Staging Environment Email Verification
On staging servers, enable Maillog to log all emails and optionally disable delivery. This allows QA teams to verify that the correct emails are being triggered by user actions without sending test emails to real addresses.
Email Debugging with Verbose Output
Enable verbose mode to see email contents directly on the page when they are sent. This is useful for debugging email templates and ensuring dynamic content is being inserted correctly.
Production Email Auditing
In production environments where email auditing is required, enable logging while keeping delivery enabled. Use the cron cleanup feature to automatically purge old logs after a set retention period to manage database size.
Database Size Management
For sites that send many emails with large bodies (like newsletters with images), enable body trimming and base64 removal to significantly reduce database storage requirements while still capturing essential email metadata.
Tips
- Use settings.php overrides to ensure Maillog configuration is environment-specific and cannot be accidentally changed in the UI
- Combine with the MailSystem module for more granular control over which mail types are logged vs. sent normally
- The Drush maillog:clear command is useful for quickly purging logs without going through the UI
- When debugging email issues, temporarily enable verbose mode to see the exact content being generated
- For staging environments, enable the 'nosend_notify' option so non-admin users know their actions didn't send real emails
Technical Details
Admin Pages 4
/admin/config/development/maillog
Main configuration page for the Maillog module where you can control email logging, delivery, and cleanup settings
/admin/reports/maillog
Views-based report page displaying all logged emails in a table format with links to view details or delete entries
/admin/reports/maillog/details/{maillog_id}
Detailed view of a single logged email showing all headers and the complete message body
/admin/reports/maillog/delete/all
Confirmation form for clearing all maillog entries from the database
Permissions 3
Hooks 2
hook_cron
Implements cron to automatically clean up old maillog entries based on configured retention settings (number or time limit).
hook_help
Provides help text for the module on the help page.
Drush Commands 1
drush maillog:clear
Clear all maillog entries from the database. Truncates the maillog table without confirmation.
Troubleshooting 4
The site's mail system may not be configured to use Maillog. Add $config['system.mail']['interface']['default'] = 'maillog'; to settings.php, or use the MailSystem module to configure mail handling.
Verify that the 'send' setting is set to FALSE in the Maillog configuration. You can hardcode this in settings.php: $config['maillog.settings']['send'] = FALSE;
Ensure the 'verbose' setting is enabled and the user viewing the page has the 'view maillog' permission. Anonymous users can see verbose output if they have this permission.
Enable the cron cleanup feature and configure appropriate retention settings. Also consider enabling body trimming and base64 removal to reduce storage per email.
Security Notes 4
- All three Maillog permissions are marked as 'restrict access' because email logs may contain sensitive information
- Be cautious about enabling verbose output in production as it could expose email contents to users with the view permission
- Email logs may contain sensitive personal information - ensure database backups and access are properly secured
- Consider the data retention implications of logging all emails and configure appropriate cleanup schedules