Simplenews SQL Sanitize
This module automatically anonymizes Simplenews subscriber email addresses when you use Drush to sanitize your database. It replaces real email addresses with synthetic ones, protecting subscriber privacy when copying databases for development or staging environments. The anonymization preserves row data for testing purposes.
Simplenews SQL Sanitize teaches Drush's sql:sanitize command how to clean up Simplenews newsletter subscriber data. If your site uses Simplenews, every subscriber's real email address lives in the database — and a plain drush sql-sanitize (or drush sql:sync) copy of that database, pulled to a laptop for local development or pushed to a staging/dev site, carries all of those real addresses along with it. This module closes that gap: install it, and the next sanitize run anonymizes subscriber emails automatically, the same way Drupal core already anonymizes user accounts.
Features
- Hooks into Drush's
sql:sanitizeevent system (SanitizeConfirmsEvent/ConsoleTerminateEvent) — no separate command to remember, it runs as part of the sanitize operation you're already running. - Anonymizes each row in
simplenews_subscriber(and its related subscription/tracking tables) to a synthetic address, mirroring how Drupal core rewritesusers_field_data.mailtouser+%[email protected]. - Anonymizes in place rather than truncating: subscriber *rows* are preserved, so newsletter admin views, subscriber counts, and stats pages still have realistic-shaped data to develop and test against — you just can't see anyone's real email address.
- Use this any time a production or production-adjacent database is copied somewhere less trusted: a developer's laptop, a shared staging server, a CI environment, or a client demo site.
- If Simplenews Stats is also installed, this module additionally anonymizes the subscriber email addresses it stores for click/open tracking — detected automatically, nothing to configure. Simplenews Stats is not required; sites without it are unaffected.
Post-Installation
There's nothing to configure. Once enabled, the module registers itself with Drush's sanitize system automatically — the next time anyone runs drush sql:sanitize (or drush sql-sanitize) against a site with this module enabled, Simplenews subscriber emails are anonymized as part of that run, alongside whatever core and any other installed sanitize-aware modules already handle. No new content type, no settings page, no permissions to grant.
Additional Requirements
- Simplenews
- Drush, with
sql:sanitizeevent-based sanitize architecture (Drush 10+)
Recommended modules/libraries
- Simplenews Stats is optionally supported.
- If your site also uses Commerce, pair this with Commerce SQL Sanitize for the same treatment of order, address, and payment method data.
Similar projects
- Simplenews Drush Sanitize addresses the same problem but was built for Drupal 7 and Drush's old hook-based sanitize system. It has a single
7.x-1.x-devrelease, hasn't seen real activity in years, and isn't compatible with the Symfony-event-basedsql:sanitizeused by modern Drush — it doesn't work on current Drupal/Drush versions. - Commerce SQL Sanitize isn't a competitor — it's the direct inspiration for this module's approach, solving the identical problem for Commerce order/address/payment data instead of Simplenews subscribers.
Supporting this Module
No funding links at this time.
Community Documentation
No configuration is required — the examples below assume Simplenews (and optionally Simplenews Stats) is already enabled.
Run a sanitize and watch for the module's own lines in the output:
drush sql-sanitize
Look for "Sanitize Simplenews subscriber email addresses." in the confirmation prompt, and "Simplenews subscriber emails sanitized." / "Simplenews mail spool truncated." in the success messages afterward.
If you want to run every other sanitize operation while skipping just this module's behavior, use these parameters:
drush sql-sanitize --sanitize-simplenews-subscribers=no --truncate-simplenews-mail-spool=no
Verify the result directly against the database:
drush sql-query "SELECT mail FROM simplenews_subscriber LIMIT 5"
Real addresses should now read like [email protected], where 42 is that row's own ID — never a real inbox.