Skip to content

Email

Email is optional. DragonslairCMS uses it for reader email verification, password resets, reader notifications and alerts to the admin team, and works without it in no-email mode.

Outgoing email uses Cloudflare’s send_email Worker binding, which needs all of:

  • The Workers Paid plan.
  • A domain on your Cloudflare account with Email Routing enabled.
  • A verified address on that domain to send from.

If any of these is missing, run in no-email mode. Everything else in the CMS works on the Free plan.

  1. Keep the send_email block in wrangler.jsonc:

    "send_email": [
    { "name": "EMAIL" }
    ]
  2. In the Cloudflare dashboard, add your domain and enable Email Routing for it.

  3. Under Email → Email Routing → Settings → Custom Addresses, add and verify the address you’ll send from.

  4. In the admin’s Settings, set Email “From” address to that address (for example My Site <hello@example.com>), make sure Site URL (canonical) is set, and leave Send outgoing email on.

The Site URL is required: every link in an email (confirmation, password reset, articles, the admin) is built from it, never from the host a request arrived on, and email stays off until it’s set. It must start https:// (see The site URL rule), and only an admin can change it.

The From address is required too. If Email “From” address is empty, the SITE_EMAIL_FROM var from wrangler.jsonc is used; with neither, email stays off. Settings refuses a From value without an @ or with a line break.

src/email.js holds everything:

  • emailEnabled(env) is true only when the EMAIL binding exists, a valid site URL and a From address are set, and the email_enabled setting isn’t 0. Every flow that depends on email checks it.
  • sendTemplatedEmail(env, key, to, vars) loads the template (a row in email_templates if the admin has customised it, otherwise the default in EMAIL_TEMPLATE_DEFAULTS), replaces {{placeholders}} with vars, and sends it as HTML with a plain-text version generated from it. An unknown placeholder is left visible in the email, so a typo is easy to spot. In the body every value is HTML-escaped, because many come from readers or anonymous visitors; the template itself is still HTML. The subject is plain text, and stripHeaderBreaks removes CR and LF from it and from the From address, so nothing can add a header line.
  • notifyAdmins(env, flag, key, vars) sends to every active CMS user whose notify_new_comment or notify_new_correction column is 1, and, for notify_new_registration, only to admins, since only they can open Readers. All three default to 1, and there’s no admin screen for them; see Running queries to turn them off for someone.

A failed send is logged with console.error and otherwise ignored, so a mail problem never breaks the request that caused it. Watch for [email] lines in npx wrangler tail if emails aren’t arriving.

Template Sent by When
verify_email src/routes/reader.js A reader registers
account_approved, account_rejected src/routes/admin-readers.js, src/routes/reader.js A reader is approved or rejected, or verifies their email when approval is off
reset_password src/routes/admin.js, src/routes/reader.js Someone asks for a reset link
new_article src/community.js An article is published for the first time, to subscribed readers
comment_reply src/routes/admin-comments.js A reply to a reader’s comment is approved, or staff reply
comment_moderated src/routes/admin-comments.js A reader’s comment is approved or rejected
admin_new_registration, admin_new_comment, admin_new_correction reader.js, api.js To the admin team

Readers can turn off new_article, comment_reply and comment_moderated in their settings; the preferences are in notification_preferences, and a missing row means on.

To change the wording, use the admin’s Email templates page (admins only) rather than the code. To add a new email, add a default to EMAIL_TEMPLATE_DEFAULTS (with a label, description and variables for the admin page) and call sendTemplatedEmail with its key.

Turn Send outgoing email off in Settings, leave the send_email block out of wrangler.jsonc, or leave the site URL or From address unset; any one puts the CMS in no-email mode. Then:

  • Admin alerts aren’t sent. New comments, corrections and registrations show as counts in the admin sidebar and on the Dashboard.
  • Reader registration skips email confirmation. New accounts are marked verified and always go into the Readers approval queue as pending, whatever New registrations require approval says, because nothing else proves the address.
  • Password resets by email are switched off, and the Forgot your password? links are hidden. Admins reset CMS users’ passwords in Users, and readers’ in Readers → Set password. The command-line seed script also resets an admin’s password.
  • Reader notifications (new articles, replies, moderation) aren’t sent.

You can switch between the modes at any time. Readers who registered in no-email mode are already verified, so turning email on later doesn’t ask them to verify.