Add env-driven SMTP and app identity settings for PocketBase

- pb_hooks/main.pb.js: bootstrap hook applying SMTP + meta settings from
  env vars on every boot (mail disabled when SMTP_HOST is unset)
- docker-compose.yml: expose SMTP_* / PB_APP_URL on the pocketbase service
- pocketbase/Dockerfile: bundle pb_hooks
- README: document the new variables
This commit is contained in:
2026-07-28 10:29:04 +02:00
parent 3d712b8c57
commit 2df1325a09
4 changed files with 62 additions and 0 deletions
+14
View File
@@ -30,6 +30,20 @@ Node >= 22.12.
| ---------------- | -------------------------------------------- | ------------------------------------ | | ---------------- | -------------------------------------------- | ------------------------------------ |
| `POCKETBASE_URL` | URL of the PocketBase backend (auth + data) | `https://pokeshare.namarusaja.me` | | `POCKETBASE_URL` | URL of the PocketBase backend (auth + data) | `https://pokeshare.namarusaja.me` |
PocketBase container (compose only):
| Variable | Description |
| ------------------------------------ | ------------------------------------------------- |
| `PB_SUPERUSER_EMAIL` / `_PASSWORD` | Create/update the admin account on boot |
| `PB_APP_URL` | Public app URL used in transactional email links |
| `SMTP_HOST` / `SMTP_PORT` | Mail server (mail disabled if `SMTP_HOST` empty) |
| `SMTP_USERNAME` / `SMTP_PASSWORD` | Mail server credentials |
| `SMTP_TLS` | `true` (default) / `false` |
| `SMTP_SENDER_NAME` / `_ADDRESS` | From header of transactional emails |
SMTP settings are applied on every boot by `pocketbase/pb_hooks/main.pb.js`
from these env vars, so they can be changed without touching the admin UI.
Read at **runtime** (`process.env`), so the same Docker image can be deployed Read at **runtime** (`process.env`), so the same Docker image can be deployed
against different PocketBase instances. For local dev, copy `.env.example` to against different PocketBase instances. For local dev, copy `.env.example` to
`.env`. `HOST` and `PORT` are also honored by the standalone server. `.env`. `HOST` and `PORT` are also honored by the standalone server.
+11
View File
@@ -11,6 +11,17 @@ services:
# Optional: create/update the admin account on boot (min 8 chars) # Optional: create/update the admin account on boot (min 8 chars)
PB_SUPERUSER_EMAIL: ${PB_SUPERUSER_EMAIL:-} PB_SUPERUSER_EMAIL: ${PB_SUPERUSER_EMAIL:-}
PB_SUPERUSER_PASSWORD: ${PB_SUPERUSER_PASSWORD:-} PB_SUPERUSER_PASSWORD: ${PB_SUPERUSER_PASSWORD:-}
# Optional: app URL used in transactional emails (reset links...)
PB_APP_URL: ${PB_APP_URL:-}
# Optional: SMTP for transactional emails. If SMTP_HOST is empty,
# mail stays disabled (the rest is ignored).
SMTP_HOST: ${SMTP_HOST:-}
SMTP_PORT: ${SMTP_PORT:-587}
SMTP_USERNAME: ${SMTP_USERNAME:-}
SMTP_PASSWORD: ${SMTP_PASSWORD:-}
SMTP_TLS: ${SMTP_TLS:-true}
SMTP_SENDER_NAME: ${SMTP_SENDER_NAME:-PokeShare}
SMTP_SENDER_ADDRESS: ${SMTP_SENDER_ADDRESS:-}
volumes: volumes:
- pb_data:/pb/pb_data - pb_data:/pb/pb_data
+1
View File
@@ -12,6 +12,7 @@ RUN curl -fsSL "https://github.com/pocketbase/pocketbase/releases/download/v${PB
&& rm pb.zip && rm pb.zip
COPY pb_migrations ./pb_migrations COPY pb_migrations ./pb_migrations
COPY pb_hooks ./pb_hooks
COPY entrypoint.sh ./ COPY entrypoint.sh ./
RUN chmod +x entrypoint.sh pocketbase RUN chmod +x entrypoint.sh pocketbase
+36
View File
@@ -0,0 +1,36 @@
/**
* Apply app identity and SMTP settings from environment variables on every
* boot, so mail config stays declarative (docker-compose / Coolify env vars).
* These values win over the admin UI (Settings → Mail) — change them via env.
*/
onBootstrap((e) => {
e.next();
const settings = $app.settings();
// App identity, used in transactional emails (verification, reset, etc.)
settings.meta.appName = "PokeShare";
const appUrl = $os.getenv("PB_APP_URL");
if (appUrl) settings.meta.appUrl = appUrl;
const host = $os.getenv("SMTP_HOST");
if (!host) {
// No SMTP configured — save identity settings and keep mail disabled
$app.save(settings);
return;
}
const senderAddress = $os.getenv("SMTP_SENDER_ADDRESS");
const senderName = $os.getenv("SMTP_SENDER_NAME");
if (senderAddress) settings.meta.senderAddress = senderAddress;
if (senderName) settings.meta.senderName = senderName;
settings.smtp.enabled = true;
settings.smtp.host = host;
settings.smtp.port = parseInt($os.getenv("SMTP_PORT") || "587", 10);
settings.smtp.username = $os.getenv("SMTP_USERNAME") || "";
settings.smtp.password = $os.getenv("SMTP_PASSWORD") || "";
settings.smtp.tls = ($os.getenv("SMTP_TLS") || "true") === "true";
$app.save(settings);
});