Email plugin settings are never read: loadDbEmailSettings queries a v2 `plugins` table that does not exist in v3
Maintainers usually reply within 1 day
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
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
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
- Fresh 3.0.0-beta.28 install on Cloudflare Workers + D1.
- Install and activate the Email plugin.
- 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 theplugindocument. - 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. initEmailServiceshort-circuits onif (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
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from SonicJs-Org/sonicjs
-
bug(admin/users): server error returns bare alert HTML causing black-shape visual artifactPossibly taken @lane711 claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
SonicJs-Org/sonicjs#1211 ·
Maintainers usually reply within 1 day
-
area: api bug priority: P2
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
SonicJs-Org/sonicjs#1200 ·
Maintainers usually reply within 1 day
-
ResendProvider cannot send on Workers: unbound `fetch` stored as an instance property throws "Illegal invocation"Possibly taken @lane711 claimed this 23 days ago. Openarea: email bug priority: P1
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SonicJs-Org/sonicjs#1099 ·
Maintainers usually reply within 1 day
-
area: documentation bug documentation priority: P2
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SonicJs-Org/sonicjs#1012 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SonicJs-Org/sonicjs#471 ·
Maintainers usually reply within 1 day
All issues in SonicJs-Org/sonicjs
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
AloisSeckar/elrh-cosca#36 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
cursor/community-plugins#572 ·
Maintainers usually reply within 1 day
-
[Plugin] calendarOpen
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
MUKE-coder/grit#228 ·
-
bug status:needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
dongdongbh/Mindwtr#1587 ·
Maintainers usually reply within 1 day