#3239·listmonk

Scheduled subscriber sync from external databases (Postgres, MySQL, MongoDB)

Author: ankit373Created Sep 25, 2026Updated Sep 25, 2026

Is your feature request related to a problem? Please describe.

Most apps using listmonk keep their users in their own database (Postgres, MySQL, MongoDB). Getting them into listmonk today means either periodic CSV exports and imports, or a custom sidecar that queries the app DB and UPSERTs into listmonk, which is what was suggested in #662. Every team ends up writing the same job: query, map columns to email/name/attribs, upsert, add to lists, schedule it, and notice when it silently stops. Subscriber freshness then depends on that glue.

Describe the solution you'd like

Admin-configured "sync sources" that run on a schedule and feed rows into the existing subimporter, so a sync behaves exactly like a CSV import with the same validation, domain blocklist and upsert semantics, just sourced from a query instead of a file.

A source would have:

  • type: postgres, mysql or mongodb
  • dsn (masked on read, like the SMTP password)
  • query: a SQL SELECT, or for MongoDB a collection plus filter and projection
  • fields: column to subscriber field map, e.g. email -> email, full_name -> name, and anything else into attribs (plan -> attribs.plan)
  • lists, subscription_status and the existing overwrite flags (overwrite_userinfo, overwrite_subscription_status) from SessionOpt
  • schedule: a cron expression (gdgvda/cron is already a dependency), or manual only
  • optional cursor_column (e.g. updated_at): the last seen value is stored per source so each run only fetches changed rows instead of the whole table

Execution:

  • SQL runs inside a read-only transaction with a statement timeout and a row cap, and the docs recommend a read-only DB user.
  • Rows are streamed in batches through the importer's existing upsert statement (SanitizeEmail, ValidateFields, list assignment all reused).
  • A run is skipped, not queued, if the importer is busy with a CSV import, since the importer is a single session.
  • Last run time, counts and the last error are kept per source and exposed over the API.
  • It never deletes or unsubscribes anyone based on a row being absent. That can be a later, explicit opt-in.

API (permission settings:manage): sources are stored in settings like SMTP and bounce mailboxes, plus POST /api/sync-sources/:id/run to trigger a run and GET /api/sync-sources/:id/status for the last result.

Dependencies: Postgres uses the existing lib/pq. MySQL adds go-sql-driver/mysql (pure Go, small). MongoDB adds the official driver, which is heavier, so I'd propose SQL sources first and MongoDB as a follow-up PR if this is accepted.

UI: given #3073, the first PR would be backend and API only. The admin screens (list sources, test connection, field mapping, run now, last result) would come after v7 on the new server-rendered admin UI.

Additional context

I have a working prototype of this against an older listmonk version and would port it to current master in small PRs. Before doing that, is this something you'd consider for core, or would you prefer it stays a separate sidecar project?