Email plugin settings are never read: loadDbEmailSettings queries a v2 `plugins` table that does not exist in v3

Open Beginner friendly
#1,098 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@lane711 is already working on this.

Since Oct 27, 2026.

  • #1145 by @lane711 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
sql, typescript
Domain
backend, database

Research direction

Start in src/services/email/db-settings.ts, where loadDbEmailSettings runs a SELECT against the non-existent plugins table and returns null from its catch block. Change the query to read settings from the documents table where type_id is 'plugin' and slug is 'email', as the issue suggests, and check that the dbSettingsFrom mapping still fits the returned shape. Also check initEmailService, which takes the DB branch. Done when the admin-saved provider is picked up on a v3 schema and the caught error is logged instead of discarded.

Written by the indexing model from the issue text.

Description

area: email bug priority: P1

Summary

The Email plugin's settings page saves the provider configuration into the plugin document (documents table), but loadDbEmailSettings() reads it from a plugins table that does not exist in the v3 schema. The query throws, the surrounding try/catch swallows it, and the email service silently falls back to the console provider. Email configured through the admin UI never sends.

Root cause

src/services/email/db-settings.ts:

async function loadDbEmailSettings(db) {
  if (!db || typeof db.prepare !== "function") return null;
  try {
    const row = await db.prepare(`SELECT settings FROM plugins WHERE id = 'email'`).first();
    ...
  } catch { return null }
}

plugins is a v2-era table. In v3 plugins are documents:

SELECT name FROM sqlite_master WHERE type='table' AND name IN ('plugins','settings');
-- 0 rows

SELECT slug, json_extract(data,'$.settings.provider') AS provider
FROM documents WHERE type_id='plugin' AND slug='email';
-- email | resend

So the settings are present and correct, in a different place than the reader looks. loadDbEmailSettings() can only ever return null on a v3 install.

Reproduction

  1. Fresh 3.0.0-beta.28 install on Cloudflare Workers + D1.
  2. Install and activate the Email plugin.
  3. In the admin UI, set provider resend, paste a Resend API key, set from/reply-to, save. The UI confirms it saved, and the values are correctly persisted in the plugin document.
  4. Click "send test".

Actual

⚠️ Email logged to console only — no provider configured.
   Set RESEND_API_KEY env var or configure a provider in Email settings.

Worker log on every isolate start:

[email] provider: fallback (console/env). EMAIL binding type: undefined | DB provider: unset

DB provider: unset even though the DB provider is set.

Expected

Provider configured through the admin UI is used, and the log reports
[email] provider: resend (DB resendApiKey).

Why this is particularly hard to diagnose

  • The settings page saves successfully and re-displays the saved values, so the configuration looks correct.
  • The error message points the user back at the exact screen they just used — "configure a provider in Email settings" — which they did.
  • The failure is swallowed by try/catch, so nothing surfaces the missing table.
  • initEmailService short-circuits on if (hasEmailService()) return, so the service is resolved once per isolate. Users who save settings and retry on a warm isolate see no change even when the underlying read does work, which sends them chasing a caching problem instead.

Suggested fix

Point the loader at the document store, e.g.:

SELECT json_extract(data, '$.settings') AS settings
FROM documents
WHERE type_id = 'plugin' AND slug = 'email'

It would also help to log the caught error rather than discarding it, so a schema drift like this is visible instead of silent.

Workaround

Configure email in code instead of through the panel, and supply the key as a Worker secret:

const config: SonicJSConfig = {
  email: {
    providerName: 'resend',
    from: 'Example <[email protected]>',
  },
  // ...
}
wrangler secret put RESEND_API_KEY

Note for anyone applying this workaround: config.email.from is required. When initEmailService takes the config branch — which it also does whenever env.RESEND_API_KEY is present — defaultFrom comes only from config.email?.from. The DB branch is the only one that calls dbSettingsFrom(dbSettings), so setting just the env var (without config.email.from) yields a provider with no default from-address.

Secondary concern: the API key is stored in plaintext

Keys entered through the settings page are persisted unencrypted in the plugin document's data JSON, readable by anyone with D1 read access (and visible in any database export or dump). Worth considering a Secrets Store binding or at minimum documenting that the env var / Worker secret path is the recommended one for production.

Environment

@sonicjs-cms/core 3.0.0-beta.28
Runtime Cloudflare Workers, D1 (remote production)
wrangler 4.131.2
node 22.22.3

Possibly related: #340 (email plugin architecture).

Dominant language
TypeScript
Stars
1.8k
Forks
219
Avg merge
2d 21h
Merged PRs (30d)
67

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SonicJs-Org/sonicjs

All issues in SonicJs-Org/sonicjs

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.