Skip to content

Add the send email possibility for webhook form with empty ressources #1

@vianmora

Description

@vianmora

When a webhooko form is parametered with no ressources, an email is send to the email user each time the form is filled.
This option, in a cloud-based option of webstudio.
So, for self-hosted instance, the repo could need a smtp service

Plan d'implémentation

Contexte technique

Quand un WebhookForm n'a pas de ressource configurée, l'action route handler appelle context.getDefaultActionResource?.() (interface définie dans extension.ts). En cloud, cette fonction appelle le propre endpoint email de Webstudio. En self-host, la fonction n'est jamais implémentée → "Resource not found".

Le publisher supporte trois modes : ssg (Vike, static), ssr (react-router-serve), docker (conteneur Docker). Seul le mode SSR/docker a un server action — le SSG est du HTML pur.

Deux repos impactés : webstudio-fork + webstudio-self-host (+ webstudio-publisher).


Étape 1 — webstudio-publisher : endpoint SMTP relay

Ajouter POST /api/form-email dans server.mjs :

  • Installe nodemailer
  • Accepte { contactEmail, fields, pageUrl, projectId } en JSON
  • Envoie via SMTP_HOST/PORT/USER/PASS/FROM/SECURE
  • Auth par Authorization: Bearer ${FORM_EMAIL_SECRET} (secret partagé)
  • Réponse { ok: true } ou { ok: false, error }

Étape 2 — webstudio-fork : implémenter getDefaultActionResource dans le template docker

Créer packages/cli/templates/react-router-docker/app/entry.server.ts qui fournit getDefaultActionResource via le load context React Router. La fonction retourne un ResourceRequest pointant vers PUBLISHER_INTERNAL_URL/api/form-email avec contactEmail + form data en body JSON, authentifié par FORM_EMAIL_SECRET.

Le publisher passe PUBLISHER_INTERNAL_URL et FORM_EMAIL_SECRET comme env vars quand il lance le conteneur SSR/docker.


Étape 3 — Mode SSG (Vike) : hors scope v1

En SSG pure, il n'y a pas de server action. Options futures :

  • Publisher intercepte les POST /_form-email dans son proxy + contactEmail dans un champ caché
  • Ou documenter que la feature nécessite le mode SSR/docker

Étape 4 — webstudio-self-host : variables d'environnement

.env.example — ajouter :

# SMTP — for form email notifications (SSR publish mode only)
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_SECURE=false
SMTP_USER=user@example.com
SMTP_PASS=yourpassword
SMTP_FROM="Webstudio Forms <noreply@example.com>"
FORM_EMAIL_SECRET=<openssl rand -hex 32>

docker-compose.yml et docker-compose.coolify.yml — service publisher :

environment:
  SMTP_HOST: ${SMTP_HOST}
  SMTP_PORT: ${SMTP_PORT:-587}
  SMTP_SECURE: ${SMTP_SECURE:-false}
  SMTP_USER: ${SMTP_USER}
  SMTP_PASS: ${SMTP_PASS}
  SMTP_FROM: ${SMTP_FROM}
  FORM_EMAIL_SECRET: ${FORM_EMAIL_SECRET}

Ordre d'exécution recommandé

  1. webstudio-publisher → endpoint /api/form-email
  2. webstudio-forkentry.server.ts + passage des env vars depuis le publisher
  3. webstudio-self-host.env.example + docker-compose

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions